Skip to content
Prev 5449 / 398502 Next

solve vs. qr.solve

gb <gb at stat.umu.se> writes:
solve.default is just another function in the base R library.
function(a, b, tol = 1e-7)
{
    if( !is.qr(a) )
	a <- qr(a, tol = tol)
    nc <- ncol(a$qr)
    if( a$rank != nc )
	stop("singular matrix `a' in solve")
    if( missing(b) ) {
	if( nc != nrow(a$qr) )
	    stop("only square matrices can be inverted")
	b <- diag(1,nc)
    }
    ## pre 0.63.3: b <- as.matrix(b)
    return(qr.coef(a,b))
}

As you can see, it checks if the first argument is a qr object and, if
not, it takes a qr decomposition.

It appears that solve.default, solve.qr, and qr.solve are identical.
I imagine the reason for identical functions under multiple names is 
for S-PLUS compatibility although I'm not sure.  Does anyone else
know?


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._