Backsolve Upper-Triangular Equations

DESCRIPTION:
Solves a system of linear equations when the matrix representing the system is upper triangular.

USAGE:
backsolve(r, x, k = ncol(r))

REQUIRED ARGUMENTS:
r:
square, upper triangular matrix. Missing values are not accepted.
x:
vector or 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.

OPTIONAL ARGUMENTS:
k:
number of columns of r to use in solving the system. The first k columns are used.

VALUE:
vector or matrix like x of the solutions y to the equations r %*% y == x. If k is smaller than the number of rows in r, then only the first k values are meaningful (the first k values in each column if x is a matrix).

DETAILS:
The lower triangle of r is not looked at (in particular, it does not need to be zero, but missing values are not allowed there).

NOTE:
Suitable r matrices can be obtained from chol and qr.

SEE ALSO:
chol , matrix , qr , solve .

EXAMPLES:
# create an upper triangular matrix
amat <- matrix(c(3,0,0,1,1,0,4,5,9), nrow = 3)
backsolve(amat, c(9,5,14))