求一个矩阵的逆矩阵,
用solve和solveCrossprod算出来的结果为神马不一样?solve算出的逆矩阵和原矩阵相乘后为单位矩阵,但是solveCrossprod算出来的却不可以...求高手们解答~
ex:
> A=matrix(rnorm(16),4,4)
> A
[,1] [,2] [,3] [,4]
[1,] 0.6284173 0.4328753 -0.02306506 2.0208425
[2,] -0.4275192 0.2264824 -1.27089533 0.4120802
[3,] -0.3335575 1.2704276 -0.57287585 -0.3561552
[4,] -1.4754065 0.9036918 0.60057038 0.6761699
> solve(A)
[,1] [,2] [,3] [,4]
[1,] 0.30706894 -0.3921209 0.32596318 -0.50706077
[2,] 0.20239678 -0.3456587 0.77125831 0.01200104
[3,] 0.04838288 -0.6554198 -0.05885997 0.22383145
[4,] 0.35655225 0.1884983 -0.26724358 0.15766370
> solveCrossprod(A)
[,1] [,2] [,3] [,4]
[1,] 0.8029294 -1.421593 -0.5911495 0.5543069
[2,] -1.4215932 3.425397 1.5890464 -1.3567095
[3,] -0.5911495 1.589046 1.5256574 -1.4231904
[4,] 0.5543069 -1.356709 -1.4231904 2.1109422
> solve(A)%*%A
[,1] [,2] [,3] [,4]
[1,] 1.000000e+00 0.000000e+00 5.551115e-17 -5.551115e-17
[2,] 4.510281e-17 1.000000e+00 6.938894e-18 -5.030698e-17
[3,] 5.551115e-17 -2.775558e-17 1.000000e+00 0.000000e+00
[4,] 2.775558e-17 2.775558e-17 1.387779e-17 1.000000e+00
之所以不用solve是因为有个矩阵不能用solve求逆矩阵,
like: 错误于solve.default(A) : 系统计算上是奇异的: 倒条件数=7.13905e-022
solve和solveCrossprod有什么区别呢?
|