(Q,R,p) = Matrices.QR(A);
This function returns the QR decomposition of a rectangular matrix A (the number of columns of A must be less than or equal to the number of rows):
Q*R = A[:,p]
where Q is a rectangular matrix that has orthonormal columns and has the same size as A (QTQ=I), R is a square, upper triangular matrix and p is a permutation vector. Matrix R has the following important properties:
This means that if abs(R[i,i]) ≤ ε then abs(R[j,k]) ≤ ε for j ≥ i, i.e., the i-th row up to the last row of R have small elements and can be treated as being zero. This allows to, e.g., estimate the row-rank of R (which is the same row-rank as A). Furthermore, R can be partitioned in two parts
A[:,p] = Q * [R1, R2; 0, 0]
where R1 is a regular, upper triangular matrix.
The solution is computed with the LAPACK functions "dgeqp3"
and "dorgqr", i.e., by Housholder transformations with
column pivoting. If Q is not needed, the function may be
called as: (,R,p) = QR(A)
.
Real A[3,3] = [1,2,3; 3,4,5; 2,1,4]; Real R[3,3]; algorithm (,R) := Matrices.QR(A); // R = [-7.07.., -4.24.., -3.67..; 0 , -1.73.., -0.23..; 0 , 0 , 0.65..];
function LQ extends Modelica.Icons.Function; input Real A[:, :] "Rectangular matrix"; output Real L[size(A, 1), size(A, 1)] "Rectangular matrix containing the lower triangular matrix"; output Real Q[size(A, 1), size(A, 2)] "Rectangular matrix with orthonormal columns such that L*Q=A"; end LQ;