Likan Zhan

行列式 (Determinant)

likan · 2017-06-16

1. 二阶和三阶行列式 (Determinant)

args(det)
## function (x, ...) 
## NULL
args(determinant)
## function (x, logarithm = TRUE, ...) 
## NULL
data <- c(3, 2, -2, 1, 12, 1)
data <- matrix(data, nrow = 2)
data
##      [,1] [,2] [,3]
## [1,]    3   -2   12
## [2,]    2    1    1
D  <- det(data[, c(1, 2)])
# Dd <- determinant(data[, c(1, 2)], logarithm = FALSE)
D1 <- det(data[, c(3, 2)])
D2 <- det(data[, c(1, 3)])
c(D, D1, D2)
## [1]   7  14 -21
x1 <- D1 / D
x2 <- D2 / D
c(x1, x2)
## [1]  2 -3
  1. 全排列和对换 (Permutations and transposition)
perm <- function(n,k){choose(n,k) * factorial(k)}
perm(3, 3)
## [1] 6