Solves a triangular system of linear equations.
backsolve(r, x, k = ncol(r), upper.tri = TRUE,
transpose = FALSE)
forwardsolve(l, x, k = ncol(l), upper.tri = FALSE,
transpose = FALSE)
| Parameter | Description |
|---|---|
r, l |
an upper (or lower) triangular matrix giving the coefficients for the system to be solved. Values below (above) the diagonal are ignored. |
x |
a matrix whose columns give the right-hand sides for the equations. |
k |
The number of columns of r and rows of x to use. |
upper.tri |
logical; if TRUE (default), the upper triangular part of r is used. Otherwise, the lower one. |
transpose |
logical; if TRUE, solve \(r' * y = x\) for \(y\), i.e., t(r) %*% y == x. |
# NOT RUN {
## upper triangular matrix 'r':
r <- rbind(c(1,2,3),
c(0,1,1),
c(0,0,2))
( y <- backsolve(r, x <- c(8,4,2)) ) # -1 3 1
r %*% y # == x = (8,4,2)
backsolve(r, x, transpose = TRUE) # 8 -12 -5
# }