QR factorization of a matrix
This functionality does not run in MATLAB.
numeric::factorQR(A
, options
)
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., R_{ij} = 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 π,
,
etc.
are accepted. They will be converted to floats, unless the option Symbolic
is
used.
The R factor is normalized such that its diagonal elements R_{ii} with i = 1, …, min(m, n) are real and nonnegative.
If no return type is specified via the option ReturnType
= d
, the domain type of the factors Q and R depends
on the type of the input matrix A
:
The factors of a dense matrix of type Dom::DenseMatrix()
are
dense matrices of type Dom::DenseMatrix()
over
the ring of expressions.
For all other matrices of categoryCat::Matrix
, the factors are returned as matrices of type Dom::Matrix()
over
the ring of MuPAD^{®} expressions. This includes input matrices A
of
type Dom::Matrix(...)
, Dom::SquareMatrix(...)
, Dom::MatrixGroup(...)
,
etc.
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)
For further processing, the factors (of domain type DOM_ARRAY
)
are converted to elements of the matrix domain Dom::Matrix
()
:
Q1 := matrix(Q1): R1 := matrix(R1): Q2 := matrix(Q2): R2 := matrix(R2):
Now, the overloaded arithmetical operators +
, *
, ^
etc.
can be used for further computations:
Q1*R1, Q2*R2
We finally verify the othogonality of the factors Q1
and Q2
:
Q1 * linalg::transpose(Q1), Q2 * linalg::transpose(Q2)
delete A, Q1, R1, Q2, R2:
We consider a nonsquare 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:
numeric::factorQR(A)
delete A:
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:

An m×n matrix
of domain type 

With With Compared to the If no 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:
If neither If Note that The trailing digits in floatingpoint results computed with
 

Prevents the conversion of the input data to floatingpoint
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.  

Suppresses warnings If symbolic coefficients are found,  

Option, specified as Return the Cholesky factor as a matrix of domain type 
List [Q, R]
with matrices Q
and R
is
returned. The domain type of the orthogonal/unitary m×m matrix Q
and
the upper triangular m×n matrix R
depends
on the type of the input matrix A
. The components
of Q
and R
are real or complex
floats, unless the option Symbolic
is used.
Householder transformations are used to compute the numerical
factorization. With the option Symbolic
, GramSchmidt
orthonormalization of the columns of A is
used.
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 Symbolic
coincide
for invertible square matrices.
For singular or nonsquare matrices, the factorization is not
unique and the results obtained with/without the option Symbolic
may
differ. Cf. Example 2.