backsolve
Backsolve Upper or Lower Triangular Equations
Description
Solves a system of linear equations when the matrix representing the
system is an upper triangular or a lower triangular.
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 | the square, upper triangular matrix. Missing values are not accepted. | 
| l | the square, lower triangular matrix. Missing values are not accepted. | 
| x | a vector or a matrix containing the right-hand sides to equations.
The length (or number of rows if a matrix) must be the same as the 
number of rows of r (even if k is smaller than 
ncol(*)). Missing values are not accepted. | 
| k | the number of columns of r to use in solving the system.
The first k columns are used. The number should be positive
and not be larger than ncol(x). | 
| upper.tri | a logical flag. If TRUE (the default), the upper triangular part of 
the matrix r is used. If FALSE, the lower part is used. | 
| transpose | a logical flag. If TRUE, the matrix r is transposed before 
calculating. If FALSE (the default), the matrix is not transposed 
before calculating. | 
 
Details
The lower or higher triangle of r is not examined. (In particular, 
it does not need to be zero, but missing values are not allowed.)
forwardsolve(l, x) is a wrapper for 
backsolve(l, x, upper.tri=FALSE).
Value
returns a vector or a matrix like 
x of the solutions 
y 
to the equations r %*% y == x.
-  If x is a vector, and k is smaller than the number of 
rows in r, then only the first k values are meaningful. 
-  If x is a matrix, and k is smaller than the number of 
columns in r, then only the first k values are meaningful.
Note
You can obtain suitable r matrices from chol and qr.
See Also
Examples
# create an upper triangular matrix
amat <- matrix(c(1,0,0,2,4,0,3,5,8), nrow = 3)
backsolve(amat, c(9,1,8))
#[1]  8 -1  1