functionQR

QR decomposition of a rectangular matrix without column pivoting (A = Q*R). Return the full square Q-matrix

Extends from Modelica.Icons.Function (Icon for functions).

Information

Syntax

(Q, R, tau, Q2) = 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

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. Matrix R has the following important properties:

  • The absolute value of a diagonal element of R is the largest value in this row, i.e., abs(R[i,i]) ≥ abs(R[i,j]).
  • The diagonal elements of R are sorted according to size, such that the largest absolute value is abs(R[1,1]) and abs(R[i,i]) ≥ abs(R[j,j]) with i < j.

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 = Q * [R1, R2;
          0,  0]

where R1 is a regular, upper triangular matrix.

Note, the solution is computed with the LAPACK function "dgeqrf", i.e., by a QR factorization without column pivoting. If Q is not needed, the function may be called as: (,R) = 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 = [-3.74.., -4.27.., -6.94..;
           0.0   , -1.64.., -0.17..;
           0.0   ,  0.0   , -1.29..]

Inputs

TypeNameDefaultDescription
Real[:,:]ARectangular matrix with size(A,1) >= size(A,2)

Outputs

TypeNameDefaultDescription
Real[size(A, 1),size(A, 2)]QRectangular matrix with orthonormal columns such that Q*R=A[:,p]
Real[min(size(A, 1), size(A, 2)),size(A, 2)]RSquare upper triangular matrix
Real[min(size(A, 1), size(A, 2))]tauScalar factors of the elementary reflectors
Real[size(A, 1),size(A, 1)]Q2Orthogonal matrix defined as the product of elementary reflectors