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


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


R语言中的det()函数用于计算指定矩阵的行列式。

用法: det(x, …)

参数:
x:矩阵

范例1:


# R program to illustrate
# det 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 det() function
det(x)

输出:

     [, 1] [, 2] [, 3]
[1, ]    3   -1    2
[2, ]    2    7    6
[3, ]    6    3   -1

[1] -185

范例2:


# R program to illustrate
# det 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
  
# Getting the transpose of the matrix x
y <- t(x)
y
  
# Calling the det() function
det(y)

输出:

     [, 1] [, 2] [, 3]
[1, ]    3   -1    2
[2, ]    2    7    6
[3, ]    6    3   -1

     [, 1] [, 2] [, 3]
[1, ]    3    2    6
[2, ]   -1    7    3
[3, ]    2    6   -1

[1] -185



相关用法


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