qqrep#
Purpose#
Computes the orthogonal-triangular (QR) decomposition of a matrix x, such that: \(X[., E] = Q_1R\)
Format#
- { q1, r, e } = qqrep(x, pvt)#
- Parameters:
x (NxP matrix) – data
pvt (Px1 vector) –
controls the selection of the pivot columns:
if \(pvt[i] > 0\), \(x[i]\) is an initial column
if \(pvt[i] = 0\), \(x[i]\) is a free column
if \(pvt[i] < 0\), \(x[i]\) is a final column
The initial columns are placed at the beginning of the matrix and the final columns are placedat the end. Only the free columns will be moved during the decomposition.
- Returns:
q1 (NxK unitary matrix) – unitary matrix,
K = min(N,P).r (KxP matrix) – upper triangular matrix
e (Px1 vector) – permutation vector
Remarks#
Given \(X[., E]\), where \(E\) is a permutation vector that permutes the columns of \(X\), there is an orthogonal matrix \(Q\) such that \(Q'X[., E]\) is zero below its diagonal, i.e.,
where \(R\) is upper triangular. If we partition
where \(Q_1\) has \(P\) columns, then
is the QR decomposition of \(X[., E]\).
qqrep() allows you to control the pivoting. For example, suppose that x is
a dataset with a column of ones in the first column. If there are
linear dependencies among the columns of x, the column of ones for the
constant may get pivoted away. This column can be forced to be included
among the linearly independent columns using pvt.
If you want only the \(R\) matrix, see qrep(). Not computing \(Q_1\) can produce
significant improvements in computing time and memory usage.
Examples#
// Create a 3x2 matrix
x = { 1 2,
3 4,
5 6 };
// Pivot vector: all columns are free
pvt = { 0, 0 };
// Compute Q1, R, and permutation vector with controlled pivoting
{ q1, r, e } = qqrep(x, pvt);
print "Q1 (orthogonal factor):";
print q1;
print "R (upper triangular):";
print r;
print "Permutation vector E:";
print e;
// Verify: Q1*R should equal x with permuted columns
print "Q1*R (should equal x[.,E]):";
print (q1 * r);
The above code produces the following output:
Q1 (orthogonal factor):
-0.26726124 0.87287156
-0.53452248 0.21821789
-0.80178373 -0.43643578
R (upper triangular):
-7.4833148 -5.8797473
0.0000000 -0.65465367
Permutation vector E:
2.0000000
1.0000000
Q1*R (should equal x[.,E]):
2.0000000 1.0000000
4.0000000 3.0000000
6.0000000 5.0000000
Source#
qqr.src