det计算矩阵的行列式

矩阵的行列式, 指正方矩阵的行列式.
计算方法参考 : 
http://zh.wikipedia.org/wiki/%E8%A1%8C%E5%88%97%E5%BC%8F
如图 : 
 对于简单的2阶和3阶的矩阵,行列式的表达式相对简单,而且恰好是每条主对角线(左上至右下)元素乘积之和减去每条副对角线(右上至左下)元素乘积之和(见图中红线和蓝线)。
2阶矩阵的行列式

3阶矩阵的行列式

在R中使用det可以迅速的得到矩阵的行列式的值.  
需要注意矩阵必须是正方矩阵.
> x <- matrix(1:12,3,4)
> x
     [,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    2    5    8   11
[3,]    3    6    9   12
> det(x)
Error in determinant.matrix(x, logarithm = TRUE, ...) : 
  'x' must be a square matrix
> x <- matrix(1:16,4,4)
> det(x)
[1] 0
> x
     [,1] [,2] [,3] [,4]
[1,]    1    5    9   13
[2,]    2    6   10   14
[3,]    3    7   11   15
[4,]    4    8   12   16
> det(t(x))
[1] 4.733165e-30
> t(x)
     [,1] [,2] [,3] [,4]
[1,]    1    2    3    4
[2,]    5    6    7    8
[3,]    9   10   11   12
[4,]   13   14   15   16


[参考]
1.  http://zh.wikipedia.org/wiki/%E8%A1%8C%E5%88%97%E5%BC%8F
2. > help(det)
det                    package:base                    R Documentation

Calculate the Determinant of a Matrix

Description:

     ‘det’ calculates the determinant of a matrix.  ‘determinant’ is a
     generic function that returns separately the modulus of the
     determinant, optionally on the logarithm scale, and the sign of
     the determinant.

Usage:

     det(x, ...)
     determinant(x, logarithm = TRUE, ...)
     
Arguments:

       x: numeric matrix: logical matrices are coerced to numeric.

logarithm: logical; if ‘TRUE’ (default) return the logarithm of the
          modulus of the determinant.

     ...: Optional arguments.  At present none are used.  Previous
          versions of ‘det’ allowed an optional ‘method’ argument.
          This argument will be ignored but will not produce an error.

Details:

     The ‘determinant’ function uses an LU decomposition and the ‘det’
     function is simply a wrapper around a call to ‘determinant’.

     Often, computing the determinant is _not_ what you should be doing
     to solve a given problem.

Value:

     For ‘det’, the determinant of ‘x’.  For ‘determinant’, a list with
     components

 modulus: a numeric value.  The modulus (absolute value) of the
          determinant if ‘logarithm’ is ‘FALSE’; otherwise the
          logarithm of the modulus.

    sign: integer; either +1 or -1 according to whether the determinant
          is positive or negative.

Examples:

     (x <- matrix(1:4, ncol = 2))
     unlist(determinant(x))
     det(x)
     
     det(print(cbind(1, 1:3, c(2,0,1))))

你可能感兴趣的:(det计算矩阵的行列式)