# Re: R-beta: solve

Simon Fear (fear@scmp.scm.liv.ac.uk)
Fri, 24 Oct 1997 11:47:20 +0100

```Date: Fri, 24 Oct 1997 11:47:20 +0100
From: fear@scmp.scm.liv.ac.uk (Simon Fear)
Message-Id: <199710241047.LAA16950@scmp.scm.liverpool.ac.uk>
To: jlindsey@luc.ac.be
Subject: Re: R-beta: solve

Content-MD5: L+YpNPzgEF6j9tN+h6Lb2g==
Sender: owner-r-help@stat.math.ethz.ch
Precedence: bulk

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@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
```