QR factorization of a matrix
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
numeric::factorQR(A) returns a QR factorization A = Q R of
the matrix A.
The QR factorization of a real/complex m×n matrix is A = Q R, where the m×m matrix Q is orthogonal/unitary and the m×n matrix R is upper triangular (i.e., Rij = 0 for j < i).
By default, a numerical factorization is computed. The matrix
must not contain symbolic objects that cannot be converted to floats.
Numerical symbolic expressions such as π,
are accepted. They will be converted to floats, unless the option
The R factor is normalized such that its diagonal elements Rii with i = 1, …, min(m, n) are real and nonnegative.
If no return type is specified via the option
= d, the domain type of the factors Q and R depends
on the type of the input matrix
The factors of a dense matrix of type
dense matrices of type
the ring of expressions.
For all other matrices of category
Cat::Matrix, the factors are returned as matrices of type
the ring of MuPAD® expressions. This includes input matrices
Without the option
Symbolic, the function
is sensitive to the environment variable
DIGITS, which determines
the numerical working precision.
We consider a quadratic matrix:
A := array(1..2, 1..2, [[1, 0] , [1, PI]]):
First, we compute a numerical factorization:
[Q1, R1] := numeric::factorQR(A)
Next, the symbolic factorization is computed:
[Q2, R2] := numeric::factorQR(A, Symbolic)
Q1 := matrix(Q1): R1 := matrix(R1): Q2 := matrix(Q2): R2 := matrix(R2):
Now, the overloaded arithmetical operators
can be used for further computations:
We finally verify the othogonality of the factors
Q1 * linalg::transpose(Q1), Q2 * linalg::transpose(Q2)
delete A, Q1, R1, Q2, R2:
We consider a non-square matrix of rank 1:
A := array(1..3, 1..2, [[0, 0], [I, 1], [I, 1]]): numeric::factorQR(A, Symbolic)
In this case, the QR factorization is not unique. Note that the numerical factorization yields different factors:
We demonstrate the difference between hardware floats and software floats. For rank deficient matrices, the QR factorization is not unique. Depending on the options, different results are returned for the following matrix of rank 1:
A := matrix([[1, 1], [10^4, 10^4], [10^8, 10^8]]): [Q1, R1] := float(numeric::factorQR(A, Symbolic))
[Q2, R2] := numeric::factorQR(A, SoftwareFloats)
[Q3, R3] := numeric::factorQR(A, HardwareFloats)
However, all factorizations satisfy A = Q R numerically:
norm(A - Q1*R1), norm(A - Q2*R2), norm(A - Q3*R3)
delete A, Q1, R1, Q2, R2, Q3, R3:
Compared to the
If the result cannot be computed with hardware floats, software arithmetic by the MuPAD kernel is tried.
If the current value of
There may be several reasons for hardware arithmetic to fail:
The trailing digits in floating-point results computed with
Prevents the conversion of the input data to floating-point
numbers. Exact arithmetic is used. This option overrides
The usual arithmetic for MuPAD expressions is used. With this option, the matrix A may contain symbolic objects.
If symbolic coefficients are found,
Option, specified as
[Q, R] with matrices
returned. The domain type of the orthogonal/unitary m×m matrix
the upper triangular m×n matrix
on the type of the input matrix
A. The components
R are real or complex
floats, unless the option
Symbolic is used.
Householder transformations are used to compute the numerical
factorization. With the option
orthonormalization of the columns of A is
For an invertible square matrix A,
the QR factorization
is unique up to scaling factors of modulus 1.
The normalization of R to
real positive diagonal elements determines the factorization uniquely.
Consequently, the results obtained with/without the option
for invertible square matrices.
For singular or non-square matrices, the factorization is not
unique and the results obtained with/without the option
differ. Cf. Example 2.