.Modelica.Math.Matrices.QR

Information

Syntax

(Q,R,p) = Matrices.QR(A);

Description

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.

Note, the solution is computed with the LAPACK functions "dgeqp3" and "dorgqr", i.e., by Householder transformations with column pivoting. If Q is not needed, the function may be called as: (,R,p) = QR(A).

Example

  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..];

Interface

function QR
  extends Modelica.Icons.Function;
  input Real A[:, :] "Rectangular matrix with size(A,1) >= size(A,2)";
  input Boolean pivoting = true "= true, if column pivoting is performed. True is default";
  output Real Q[size(A, 1), size(A, 2)] "Rectangular matrix with orthonormal columns such that Q*R=A[:,p]";
  output Real R[size(A, 2), size(A, 2)] "Square upper triangular matrix";
  output Integer p[size(A, 2)] "Column permutation vector";
end QR;

Generated at 2024-11-21T19:25:40Z by OpenModelicaOpenModelica 1.24.2 using GenerateDoc.mos