backsolve {base} | R Documentation |
Solve an Upper or Lower Triangular System
Description
Solves a triangular system of linear equations.
Usage
backsolve(r, x, k = ncol(r), upper.tri = TRUE,
transpose = FALSE)
forwardsolve(l, x, k = ncol(l), upper.tri = FALSE,
transpose = FALSE)
Arguments
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 |
upper.tri |
logical; if |
transpose |
logical; if |
Details
Solves a system of linear equations where the coefficient matrix is upper (or ‘right’, ‘R’) or lower (‘left’, ‘L’) triangular.
x <- backsolve (R, b)
solves R x = b
, and
x <- forwardsolve(L, b)
solves L x = b
, respectively.
The r
/l
must have at least k
rows and columns,
and x
must have at least k
rows.
This is a wrapper for the level-3 BLAS routine dtrsm
.
Value
The solution of the triangular system. The result will be a vector if
x
is a vector and a matrix if x
is a matrix.
References
Becker RA, Chambers JM, Wilks AR (1988). The New S Language. Chapman and Hall/CRC, London.
Dongarra J, Bunch J, Moler C, Stewart G (1979). LINPACK Users' Guide, series Other Titles in Applied Mathematics. Society for Industrial and Applied Mathematics. ISBN 9780898711721. doi:10.1137/1.9780898719604.
See Also
Examples
## 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