R语言 获取矩阵的行列式模数 – determinant() 函数
R语言中的 determinant() 函数是一个通用函数,可以分别返回行列式的模数,可以选择对数尺度,以及行列式的符号。
语法: 行列式(x, logarithm = TRUE, …)
参数:
x: 矩阵
logarithm: 如果为TRUE(默认),则返回行列式的模数的对数。
例1 :
# R program to illustrate
# determinant function
# Initializing a matrix with
# 3 rows and 3 columns
x <- matrix(c(3, 2, 6, -1, 7, 3, 2, 6, -1), 3, 3)
# Getting the matrix representation
x
# Calling the determinant() function
determinant(x)
输出
[, 1] [, 2] [, 3]
[1, ] 3 -1 2
[2, ] 2 7 6
[3, ] 6 3 -1
modulus
[1] 5.220356
attr(, "logarithm")
[1] TRUEsign
[1] -1
attr(, "class")
[1] "det"
例2 :
# R program to illustrate
# determinant function
# Initializing a matrix with
# 2 rows and 2 columns
x <- matrix(c(1, 2, 3, 4), 2, 2)
# Getting the matrix representation
x
# Calling the determinant() function
determinant(x, logarithm = FALSE)
输出
[, 1] [, 2]
[1, ] 1 3
[2, ] 2 4
modulus
[1] 2
attr(, "logarithm")
[1] FALSEsign
[1] -1
attr(, "class")
[1] "det"