qrsol#
Purpose#
Computes the solution of \(Rx = b\) where \(R\) is an upper triangular matrix.
Format#
- x = qrsol(b, R)#
- Parameters:
b (PxL matrix) – data
R (PxP matrix) – upper triangular matrix
- Returns:
x (PxL matrix) – solution of \(Rx = b\) where \(R\) is an upper triangular matrix.
Remarks#
qrsol() applies a backsolve to \(Rx = b\) to solve for x. Generally R will be
the R matrix from a QR factorization. qrsol() may be used, however, in any situation
where R is upper triangular.
Examples#
// Upper triangular matrix R and right-hand side b
r = { 3 1,
0 2 };
b = { 7, 4 };
// Solve R*x = b
x = qrsol(b, r);
print "Solution x:";
print x;
print "R*x (should equal b):";
print (r * x);
The above code produces the following output:
Solution x:
1.6666667
2.0000000
R*x (should equal b):
7.0000000
4.0000000
Source#
qrsol.src