當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。