matrix_det

Computes the determinant of a square real-valued matrix.

Synopsis

#include <imsl.h>

float imsl_f_matrix_det (int n, float a[], ..., 0)

The type double function is imsl_d_matrix_det.

Required Arguments

int n (Input)
The number of rows and columns in matrix A.

float a[] (Input)
Matrix for which the determinant is calculated.

Return Value

The determinant of a. If IMSL_RETURN_LOG is specified, the log of the absolute value of the determinant. If the return value cannot be computed, NaN is returned.

Synopsis with Optional Arguments

#include <imsl.h>

float  imsl_f_matrix_det (int n, float a[],

IMSL_SYMMETRIC,

IMSL_TOLERANCE, float tol,

IMSL_RETURN_LOG, float *s,

0)

Optional Arguments

IMSL_SYMMETRIC,
If specified, the input matrix is expected to be symmetric, and this property will be exploited in the calculation of the eigenvalues.

IMSL_TOLERANCE, float tol (Input)
Scalar containing the tolerance used to determine when an eigenvalue is negligible and replaced by the value zero. A zero or negligible eigenvalue implies that the input matrix is singular and has zero determinant.

Default: tol = 100.0 * imsl_f_machine(4)

IMSL_RETURN_LOG, float *s (Output)
If specified, the log of the modulus of the determinant is returned in the return value, and the sign of the determinant is returned in s.

Description

Let A be a real-valued square matrix with n rows and columns. The determinant of A, denoted by det(A) or |A|, is a scalar function that characterizes the matrix and its behavior as a linear operator. There are several ways to calculate the determinant. Based on the characteristic equation that is used to find the eigenvalues of a matrix, it follows that

where λi are the n (real or complex) eigenvalues of A. This function first finds the eigenvalues and then takes their product to obtain the determinant of A. See imsl_f_eig_gen and imsl_f_eig_sym.

Example 1

The following example finds the determinant of a 4x4 matrix.

#include <imsl.h>
#include <stdio.h>

int main()
{
     float deta;
  int n = 4;

  float a[] = { 5.0, 5.0, -6.0, -7.0,
              3.0, 6.0, -5.0, -6.0,
              2.0, 3.0, -1.0, -5.0,
              1.0, 2.0, -3.0, 0.0 };

  
  deta = imsl_f_matrix_det(n, a, 0);
  
  printf("The determinant = %f\n", deta);
 
}

Output

The determinant = 24.000000

Example 2

The following example finds the determinant and log determinant of a 4x4 symmetric matrix.

#include <imsl.h>
#include <stdio.h>

int main()
{
     float deta, ldeta, s;
  int n = 4;

  float a[] = { 5.0, 5.0, -6.0, -7.0,
                5.0, 6.0, -5.0, -6.0,
               -6.0, -5.0, -1.0, -5.0,
               -7.0, -6.0, -5.0, 0.0 };

   
  deta = imsl_f_matrix_det(n, a, 0);
  
  printf("The determinant = %f\n", deta);

  deta = imsl_f_matrix_det(n, a,IMSL_SYMMETRIC, 0);
  
  printf("The determinant using optional argument = %f\n", deta);

  ldeta = imsl_f_matrix_det(n, a, IMSL_RETURN_LOG, &s, 0);
  
  printf("The log |determinant| = %f, sign = %f\n", ldeta ,s);
  
}
 

Output

The determinant = -540.000000
The determinant using optional argument = -540.000000
The log |determinant| = 6.291569, sign = -1.000000

Fatal Errors

IMSL_ZERO_DETERMINANT

The input matrix is singular. NaN is returned for the log determinant.