[R] Need help to locate my mistake
Louise Hoffman
louise.hoffman at gmail.com
Mon Mar 3 00:49:54 CET 2008
> Unfortunately, x^(-1) is not the inverse of x:
>
> x<-matrix(c(2,4,4,5),nrow=2)
> x
> # [,1] [,2]
> # [1,] 2 4
> # [2,] 4 5
>
> x^(-1)
> # [,1] [,2]
> # [1,] 0.50 0.25
> # [2,] 0.25 0.20
>
> i.e. it is the matrix which you get by applying the operation
> (...)^(-1) to each element of x.
>
> In R, the inverse of a non-singular matrix is (somewhat obscurely)
> denoted by solve(x):
>
> solve(x)
> # [,1] [,2]
> # [1,] -0.8333333 0.6666667
> # [2,] 0.6666667 -0.3333333
>
> solve(x)%*%x
> # [,1] [,2]
> # [1,] 1 1.110223e-16
> # [2,] 0 1.000000e+00
> (Note the slight rounding error); whereas
>
> (x^(-1))%*%x
> # [,1] [,2]
> # [1,] 2.0 3.25
> # [2,] 1.3 2.00
Thanks for the very detailed explanation! I will never make that
mistake again =)
More information about the R-help
mailing list