NCL Website header
NCL Home > Documentation > Functions > General applied math

determinant

Calculates the determinant of a square real matrix.

Available in version 6.3.0 and later.

Prototype

	function determinant (
		x [*][*] : numeric   
	)

	return_val [1] :  float or double

Arguments

x

A two-dimensional variable of numeric type. The dimension sizes must be the same (i.e. [N][N])

Return value

A scalar of type double if x is type double; otherwise the returned value will be type float.

Description

Normally, NCL would use an LAPACK code to compute a mathematical quantity such as the determinant. However, LAPACK contains no such subroutine due to issues with accuracy and stability:

   http://www.netlib.org/lapack/faq.html#_are_there_routines_in_lapack_to_compute_determinants
Basically, numerical analysts do not want people calculating the determinant.

NCL uses a fortran subroutine from:


    An Introduction to  Computational Physics  
    Tao Pang 
    Cambridge University Press, 1997

Specifically, the determinant of the square (NxN) matrix is calculated using the partial-pivoting Gaussian elimination scheme.

WARNING: This subroutine has been tested using small array sizes only.

See Also

solve_linsys

Examples

Example 1

   a = (/ (/ 1, 0, 2, -1/) \   ; N=4
        , (/ 3, 0, 0,  5/) \
        , (/ 2, 1, 4, -3/) \
        , (/ 1, 0, 5,  0/) /)

   d = determinant(a)          ; d=30.0