当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R语言 determinant()用法及代码示例


R 语言中的 determinant() 函数是一个通用函数,它分别返回行列式的模数(可选对数刻度)和行列式的符号。

用法: 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] TRUE

$sign
[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] FALSE

$sign
[1] -1

attr(, "class")
[1] "det"

相关用法


注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 Getting the Modulus of the Determinant of a Matrix in R Programming – determinant() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。