矩阵求逆R [英] matrix inversion R
本文介绍了矩阵求逆R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想对一个平方对称正定矩阵求逆.我知道R中有两个函数solve()
和chol2inv()
,但是它们的结果不同.我需要知道为什么会这样吗?
I want to inverse a square symmetric positive definite matrix. I know there are two functions solve()
and chol2inv()
in R but their results is different. I need to know why this happen?
谢谢.
推荐答案
对于solve
,您需要给出原始矩阵,但对于chol2inv
,则使用预先计算的cholesky分解:
For solve
you need to give your original matrix, but for chol2inv
you use precomputed cholesky decomposition:
set.seed(1)
a<-crossprod(matrix(rnorm(9),3,3))
a_chol<-chol(a)
solve(a)
[,1] [,2] [,3]
[1,] 1.34638151 -0.02957435 0.8010735
[2,] -0.02957435 0.32780020 -0.1786295
[3,] 0.80107345 -0.17862950 1.4533671
chol2inv(a_chol)
[,1] [,2] [,3]
[1,] 1.34638151 -0.02957435 0.8010735
[2,] -0.02957435 0.32780020 -0.1786295
[3,] 0.80107345 -0.17862950 1.4533671
这篇关于矩阵求逆R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文