On Wed, Jun 18, 2014 at 2:26 PM, Judson wrote:
> Dear Dr. Bates,
> I'm just learning R and I want to use it for
> statistical problems and also some problems
> that are just mathematical. Apparently I'm
> not using the packages right and none of the
> books I've found cover what should be simple
> operation, inverting a matrix. Can you point
> me in the right direction?
> ..................... judson blake
>
It is usually more effective to submit questions like this to the
R-help@R-Project.org mailing list which I am cc:ing on this reply. Many
people who read that list can respond and usually much faster than I do.
The short answer to your question is
solve(A)
> A <- matrix(rnorm(16),nc=4)> Ainv <- solve(A)> zapsmall(Ainv %*% A) [,1] [,2] [,3] [,4]
[1,] 1 0 0 0
[2,] 0 1 0 0
[3,] 0 0 1 0
[4,] 0 0 0 1
The longer answer to your question is that you may think you need to
calculate the inverse of a matrix but you probably don't. Inverses occur
frequently in formulas and much less frequently in actual computation that
has a chance of scaling well. In numerical linear algebra one factorizes a
matrix and works with the factors.
[[alternative HTML version deleted]]