File: solvet.s

package info (click to toggle)
hmisc 5.2-5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,044 kB
  • sloc: asm: 28,907; f90: 590; ansic: 415; xml: 160; fortran: 75; makefile: 2
file content (22 lines) | stat: -rw-r--r-- 410 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#FEH version of solve with argument tol passed to qr
#8 Apr 91

solvet <- function(a, b, tol=1e-9)
{
  if(!is.list(a))
    a <- qr(a, tol=tol)

  if(a$rank < ncol(a$qr))
    stop("apparently singular matrix")

  if(missing(b)) {
    b <- a$qr
    db <- dim(b)
    if(diff(db))
      stop("matrix inverse only for square matrices")

    b[] <- rep(c(1, rep(0, db[1])), length = prod(db))
  }

  qr.coef(a, b)
}