Inverse of matrix in R

前端 未结 3 606
执念已碎
执念已碎 2021-01-30 03:46

I was wondering what is your recommended way to compute the inverse of a matrix?

The ways I found seem not satisfactory. For example,

> c=rbind(c(1,          


        
3条回答
  •  渐次进展
    2021-01-30 04:25

    Note that if you care about speed and do not need to worry about singularities, solve() should be preferred to ginv() because it is much faster, as you can check:

    require(MASS)
    mat <- matrix(rnorm(1e6),nrow=1e3,ncol=1e3)
    
    t0 <- proc.time()
    inv0 <- ginv(mat)
    proc.time() - t0 
    
    t1 <- proc.time()
    inv1 <- solve(mat)
    proc.time() - t1 
    

提交回复
热议问题