SLogDet

Compute the sign and logarithm of the determinant of a square invertible matrix.

double matrix::SLogDet(
  int&       sign       // sign
  double&    log_det    // logarithm of the determinant
   );
 
double matrix<complex>::SLogDet(
  complex&   sign       // sign
  double&    log_det    // logarithm of the determinant
   );

Parameters

sign

[out]  Factor by which the determinant can be reconstructed as sign*exp(log_det). For a real matrix, contains the determinant sign. The sign value is zero in case of an error or a singular matrix.

log_det

[out]  Calculated value of the logarithm of the determinant. For a singular matrix, log_det is negative infinity.

Return Value

The matrix determinant, as if calculated by the Det method. In case of an error, 0 is returned.

Note

The determinant is calculated by the Gaussian method by reducing the matrix to an upper triangular form. The determinant of an upper triangular matrix is equal to the product of the main diagonal elements. The logarithm of a product is equal to the sum of the logarithms. Therefore, in case of an overflow when calculating the determinant, you can use the SLogDet method.

The determinant value can be reconstructed using the formula det=sign*exp(log_det).

MQL5 example:

void OnStart()
 {
 MathSrand(12345);
 ulong M=8;
 ulong N=8;
 matrixc a=matrixc::Random(M,N,0.5,2+0.1i);
 complex sign;
 double log_det;
 complex det=a.Det();
 Print("det=",det);
 complex det1=a.SLogDet(sign,log_det);
 Print("det1=",det1," sign=",sign," log_det=",log_det);
 complex det2=sign*MathExp(log_det);
 Print("det2=",det2);
 }

Expert log output

 det=(-13.10918456377537,2.055678770471468)
 det1=(-13.10918456377537,2.055678770471468) sign=(-0.9879271850078791,0.1549189372620642) log_det=2.585459379616607
 det2=(-13.10918456377537,2.055678770471469)