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


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