R-beta: solve

Simon Fear fear at scmp.scm.liv.ac.uk
Fri Oct 24 12:47:20 CEST 1997


Silly me thinking solve code wasn't accessible in R (cos it isn't in S-PLUS). All you 
need is a tiny edit:

> mysolve
function (a, b, tol = 1e-07) 
{
        if (!is.qr(a)) 
                a <- qr(a, tol = tol)
        nc <- ncol(a$qr)
        if (a$rank != nc) {
                warning("singular matrix \'a\' in solve")
                return(rep(NA, nc))
        }
        if (missing(b)) {
                if (nc != nrow(a$qr)) {
                        warning("only square matrices can be inverted")
                        return(rep(NA, nc))
                }
                b <- diag(1, nc)
        }
        b <- as.matrix(b)
        return(qr.coef(a, b))
}

Well, not quite all; if b is the wrong length, you'll still get a fatal error 
from qr.coef, but that's just as easily edited.

Advise Jim (and anybody else) to edit nlm into mynlm with a call to mysolve (and 
a subsequent test that !is.na(ans[1]); you might get very strange 
compatability/porting problems if you overwrite the default solve.

Simon Fear
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



More information about the R-help mailing list