[R] How could I find the inverse of a matrix?

Steve Lianoglou mailinglist.honeypot at gmail.com
Fri Dec 11 17:30:43 CET 2009


Hi Moohwan,

On Dec 11, 2009, at 11:26 AM, Moohwan Kim wrote:

> Dear R family
> 
> I have a following question.
> Suppose I have a matrix as follows, for instance:
> tau=
> 0 0 0 0 1
> 1 0 0 0 0
> 0 1 0 0 0
> 0 0 1 0 0
> 0 0 0 1 0
> 
> I want to have the inverse of the above matrix and then add some
> exponent to it. That is, I want to calculate tau to the (-m). For
> example, m=893.

If you *really* want the inverse, use the `solve` function without a second parameter:

R> tau <- c(0, 0, 0, 0, 1,
         1, 0, 0, 0, 0,
         0, 1, 0, 0, 0,
         0, 0, 1, 0, 0,
         0, 0, 0, 1, 0)
R> tau <- matrix(tau, ncol=5, byrow=TRUE)
R> tau %*% solve(tau)
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    0    0    0    0
[2,]    0    1    0    0    0
[3,]    0    0    1    0    0
[4,]    0    0    0    1    0
[5,]    0    0    0    0    1

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact




More information about the R-help mailing list