R의 역행렬
Sheeraz Gul
2023년6월21일
R
R Matrix

R에서 역을 계산하는 두 가지 방법이 있습니다. 첫 번째는 기본 R의 solve
함수이고 다른 하나는 matlib
라이브러리의 inv()
메서드입니다. 이 튜토리얼은 R에서 역행렬을 찾는 두 가지 방법을 보여줍니다.
Solve
를 사용하여 R에서 역행렬 찾기
solve()
메서드는 행렬을 매개변수로 사용하고 주어진 행렬의 역행렬을 출력합니다. 예를 참조하십시오:
x1 <- c(10, 8, 4)
x2 <- c(7, 9, 3)
x3 <- c(11, 2, 5)
# bind the matrix
A <- rbind(x1, x2, x3)
# the original matrix
print(A)
# calculate the inverse.
Inverse_Matrix <- solve(A)
# the inverse of the matrix.
print(Inverse_Matrix)
위의 코드는 solve()
를 사용하여 주어진 행렬의 역수를 계산합니다. 출력 참조:
[,1] [,2] [,3]
x1 10 8 4
x2 7 9 3
x3 11 2 5
x1 x2 x3
[1,] 1.14705882 -0.9411765 -0.35294118
[2,] -0.05882353 0.1764706 -0.05882353
[3,] -2.50000000 2.0000000 1.00000000
Matlib
에서 Inv()
를 사용하여 R에서 역행렬 찾기
Matlib
라이브러리에는 역행렬을 찾을 수 있는 inv()
함수가 있습니다. 예를 들어 보겠습니다.
install.packages('matlib')
library(matlib)
x1 <- c(10, 8, 4)
x2 <- c(7, 9, 3)
x3 <- c(11, 2, 5)
# bind the matrix
A <- rbind(x1, x2, x3)
# the original matrix
print(A)
# calculate the inverse.
print(inv(t(A)))
위 코드의 출력은 원래 행렬과 역행렬이 됩니다. 출력을 참조하십시오.
[,1] [,2] [,3]
x1 10 8 4
x2 7 9 3
x3 11 2 5
[1,] 1.14705882 -0.9411765 -0.35294118
[2,] -0.05882353 0.1764706 -0.05882353
[3,] -2.50000000 2.0000000 1.00000000
튜토리얼이 마음에 드시나요? DelftStack을 구독하세요 YouTube에서 저희가 더 많은 고품질 비디오 가이드를 제작할 수 있도록 지원해주세요. 구독하다
작가: Sheeraz Gul
Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.
LinkedIn Facebook