[R] Change in 'solve' for r-patched

Douglas Bates bates at stat.wisc.edu
Thu Oct 30 20:59:00 CET 2003


Douglas Bates <bates at cs.wisc.edu> writes:

...
> To begin with, you don't invert a matrix just to solve a system of
> equations.  If A is an n by n matrix and y is an n vector, then
> 
>  solve(A)
> 
> is the equivalent of performing
> 
>  solve(A, y)
> 
> n times.  Thus solve(A) %*% y is more than n times as expensive as
> solve(A, y).  If you want A^{-1}y then write it as solve(A, y).

I overstated the comparison between solve(A, y) and solve(A) %*% y.
For both solve(A) and solve(A, y), the first step is to calculate
an LU decomposition of A, and the second step is to solve the linear
system(s) of equations using this decomposition.  It is only the second
step that takes n times as long for solve(A) than it does for solve(A, y)
(when y is a vector).  

The first step, which will account for the majority of the time spent
executing solve(A, y), is the same as in solve(A).




More information about the R-help mailing list