inv()
R語言中的函數用於計算矩陣的逆。
Note: Determinant of the matrix must not be zero
用法: inv(x)
參數:
x:矩陣
範例1:
# R program to calculate
# inverse of a matrix
# Loading library
library(matlib)
# Create 3 different vectors.
a1 <- c(3, 2, 8)
a2 <- c(6, 3, 2)
a3 <- c(5, 2, 4)
# Bind the 3 matrices row-wise
# using the rbind() function.
A <- rbind(a1, a2, a3)
# find inverse using the inv() function.
print(inv(A))
輸出:
[, 1] [, 2] [, 3] [1, ] -0.2857143 -0.2857143 0.7142857 [2, ] 0.5000000 1.0000000 -1.5000000 [3, ] 0.1071429 -0.1428571 0.1071429
範例2:
# R program to calculate
# inverse of a matrix
# Loading Library
library(matlib)
# Creating a matrix
A = matrix(c(2, 5, 3, 4, 5, 2, 6, 3, 4), 3, 3)
det(A)
# Calling inv() function
cat("Inverse of A:\n")
inv(A)
輸出:
[1] -46 Inverse of A: [, 1] [, 2] [, 3] [1, ] -0.3043478 0.08695652 0.3913044 [2, ] 0.2391304 0.21739130 -0.5217391 [3, ] 0.1086957 -0.17391304 0.2173913
相關用法
- R語言 asin()用法及代碼示例
- R語言 acos()用法及代碼示例
- R語言 atan()用法及代碼示例
- R語言 is.matrix()用法及代碼示例
- R語言 data.matrix()用法及代碼示例
- R語言 as.matrix()用法及代碼示例
- R語言 nchar()用法及代碼示例
- R語言 determinant()用法及代碼示例
- R語言 lower.tri()用法及代碼示例
- R語言 dim()用法及代碼示例
- R語言 colSums()用法及代碼示例
- R語言 col()用法及代碼示例
- R語言 colMeans()用法及代碼示例
- R語言 det()用法及代碼示例
- R語言 diag()用法及代碼示例
注:本文由純淨天空篩選整理自nidhi_biet大神的英文原創作品 Finding Inverse of a Matrix in R Programming – inv() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。