|
矩阵求逆
矩阵求逆可用函数solve(),应用solve(a, b)运算结果是解线性方程组ax = b,
若b缺省,则系统默认为单位矩阵,因此可用其进行矩阵求逆,例如:
> a=matrix(rnorm(16),4,4)
> a
[,1] [,2] [,3] [,4]
[1,] 1.6986019 0.5239738 0.2332094 0.3174184
[2,] -0.2010667 1.0913013 -1.2093734 0.8096514
[3,] -0.1797628 -0.7573283 0.2864535 1.3679963
[4,] -0.2217916 -0.3754700 0.1696771 -1.2424030
> solve(a)
[,1] [,2] [,3] [,4]
[1,] 0.9096360 0.54057479 0.7234861 1.3813059
[2,] -0.6464172 -0.91849017 -1.7546836 -2.6957775
[3,] -0.7841661 -1.78780083 -1.5795262 -3.1046207
[4,] -0.0741260 -0.06308603 0.1854137 -0.6607851
> solve (a) %*%a
[,1] [,2] [,3] [,4]
[1,] 1.000000e+00 2.748453e-17 -2.787755e-17 -8.023096e-17
[2,] 1.626303e-19 1.000000e+00 -4.960225e-18 6.977925e-16
[3,] 2.135878e-17 -4.629543e-17 1.000000e+00 6.201636e-17
[4,] 1.866183e-17 1.563962e-17 1.183813e-17 1.000000e+00 |
|