det计算矩阵的行列式

矩阵的行列式, 指正方矩阵的行列式.
计算方法参考 : 
如图 : 
det计算矩阵的行列式 - 德哥@Digoal - PostgreSQL research
 对于简单的2阶和3阶的矩阵,行列式的表达式相对简单,而且恰好是每条主对角线(左上至右下)元素乘积之和减去每条副对角线(右上至左下)元素乘积之和(见图中红线和蓝线)。
2阶矩阵的行列式
det计算矩阵的行列式 - 德哥@Digoal - PostgreSQL research

3阶矩阵的行列式
det计算矩阵的行列式 - 德哥@Digoal - PostgreSQL research

在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))))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值