Main Content

QR Factorization

Factor arbitrary matrix into unitary and upper triangular components

  • QR Factorization block

Libraries:
DSP System Toolbox / Math Functions / Matrices and Linear Algebra / Matrix Factorizations

Description

The QR Factorization block uses a sequence of Householder transformations to triangularize the input matrix A.

QR factorization is an important tool for solving linear systems of equations because of good error propagation properties and the invertibility of unitary matrices:

Q –1 = Q '

where Q' is the complex conjugate transpose of Q.

Unlike LU and Cholesky factorizations, the matrix A does not need to be square for QR factorization. However, QR factorization requires twice as many operations as LU Factorization (Gaussian elimination).

For more details on how the block performs the QR factorization, see Algorithms.

Examples

expand all

The Output size parameter of the QR factorization block has two settings: Economy and Full. When the M-by-N input matrix A has dimensions such that M > N, the dimensions of output matrices Q and R differ depending on the setting of the Output size parameter. However, if the size of the input matrix A is such that M is less than or equal to N, output matrices Q and R have the same dimensions, regardless of whether the Output size is set to Economy or Full.

The input to the QR Factorization block in the following model is a 5-by-2 matrix A. When you change the setting of the Output size parameter from Economy to Full, the dimensions of the output given by the QR Factorization block also change.

Open the ex_qrfactorization_ref model.

Double-click the QR Factorization block, set the Output size parameter to Economy, and run the model.

The QR Factorization block outputs a 5-by-2 matrix Q and a 2-by-2 matrix R.

Change the Output size parameter of the QR Factorization block to Full and rerun the model. The QR Factorization block outputs a 5-by-5 matrix Q and a 5-by-2 matrix R.

Ports

Input

expand all

Specify the input as a vector or a matrix of size M-by-N.

The block treats length-M unoriented vector input as an M-by-1 matrix.

Data Types: single | double
Complex Number Support: Yes

Output

expand all

Orthonormal component Q of QR factorization, returned as a vector or a matrix. The size of Q depends on the setting of the Output size parameter:

The size of Q depends on the setting of the Output size parameter:

  • When you select Economy for the output size, Q is an M-by-min(M,N) unitary matrix.

    [Q R E] = qr(A,0)   % Equivalent MATLAB code

  • When you select Full for the output size, Q is an M-by-M unitary matrix.

    [Q R E] = qr(A)      % Equivalent MATLAB code

Data Types: single | double
Complex Number Support: Yes

Upper triangular component R of QR factorization, returned as a vector or a matrix.

The size of R depends on the setting of the Output size parameter:

  • When you select Economy for the output size, R is a min(M,N)-by-N upper-triangular matrix.

    [Q R E] = qr(A,0)   % Equivalent MATLAB code

  • When you select Full for the output size, R is a M-by-N upper-triangular matrix.

    [Q R E] = qr(A)      % Equivalent MATLAB code

Data Types: single | double
Complex Number Support: Yes

Column permutation vector E of length N, where N is the number of columns in the input matrix.

The block selects a column permutation vector which ensures that the diagonal elements of matrix R are arranged in order of decreasing magnitude.

|ri+1,j+1|<|ri,j|        i=j

For more details on how the block uses this vector, see Algorithms.

Data Types: single | double

Parameters

expand all

Specify the size of output matrices Q and R:

  • Economy — When you select this output size, the block outputs an M-by-min(M,N) unitary matrix Q and a min(M,N)-by-N upper-triangular matrix R.

  • Full — When you select this output size, the block outputs an M-by-M unitary matrix Q and a M-by-N upper-triangular matrix R.

Specify the type of simulation to run. You can set this parameter to:

  • Interpreted execution –– Simulate model using the MATLAB® interpreter. This option shortens startup time.

  • Code generation –– Simulate model using generated C code. The first time you run a simulation, Simulink® generates C code for the block. The C code is reused for subsequent simulations as long as the model does not change. This option requires additional startup time but provides faster subsequent simulations.

Block Characteristics

Data Types

double | single

Direct Feedthrough

no

Multidimensional Signals

no

Variable-Size Signals

no

Zero-Crossing Detection

no

Algorithms

The block factors a column permutation of the M-by-N input matrix A as A e = QR.

The column-pivoted matrix Ae contains the columns of A permuted as indicated by the contents of length-N permutation vector E.

Here is the equivalent MATLAB code.

Ae = A(:,E)

The block selects a column permutation vector E which ensures that the diagonal elements of matrix R are arranged in order of decreasing magnitude.

|ri+1,j+1|<|ri,j|        i=j

The size of matrices Q and R depends on the setting of the Output size parameter:

  • When you select Economy for the output size, Q is an M-by-min(M,N) unitary matrix, and R is a min(M,N)-by-N upper-triangular matrix.

    [Q R E] = qr(A,0)   % Equivalent MATLAB code

  • When you select Full for the output size, Q is an M-by-M unitary matrix, and R is a M-by-N upper-triangular matrix.

    [Q R E] = qr(A)      % Equivalent MATLAB code

References

[1] Golub, G. H., and C. F. Van Loan. Matrix Computations. 3rd ed. Baltimore, MD: Johns Hopkins University Press, 1996.

Extended Capabilities

Version History

Introduced before R2006a