## `numeric::factorQR` -- QR factorization of a matrix

#### Introduction

`numeric::factorQR``(A, ..)` returns a QR factorization A=QR of the matrix A.

#### Call(s)

`numeric::factorQR(A <, Symbolic>)`

#### Parameters

`A` | - | an m x n matrix of domain type `DOM_ARRAY` or of category `Cat::Matrix`

#### Options

`Symbolic` | - | prevents `numeric::factorQR` from using floating point arithmetic

#### Returns

The list `[Q,R]` with `Q` and `R` of domain type `DOM_ARRAY` is returned. The components of `Q` and `R` are real or complex floats, unless the option Symbolic is used.

#### Side Effects

The function is sensitive to the environment variable `DIGITS`, which determines the numerical working precision.

#### Related Functions

`linalg::factorQR`, `numeric::factorCholesky`, `numeric::factorLU`

#### Details

- The QR factorization of a real/complex m x n matrix is A=QR, where the m x m matrix Q is orthogonal/unitary and the m x n matrix R is upper triangular (i.e., R[i,j]=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 `PI`, `sqrt(2)`, `exp(-1)` 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[i,i] with i=1..min(m,n) are real and nonnegative.

#### Option: Symbolic

- This option prevents conversion of the matrix entries to floats. The usual arithmetic for MuPAD expressions is used. With this option the matrix A may contain symbolic objects.

#### Example 1

We consider the matrix

    >> A := array(1..2, 1..2, [[1, 0] , [1, PI]]):

First we compute a numerical factorization:

    >> [Q1, R1] := numeric::factorQR(A)

          -- +-                             -+
          |  |  0.7071067812, -0.7071067812  |
          |  |                               |,
          |  |  0.7071067812,  0.7071067812  |
          -- +-                             -+

             +-                          -+ --
             |  1.414213562, 2.221441469  |  |
             |                            |  |
             |       0,      2.221441469  |  |
             +-                          -+ --

Next the symbolic factorization is computed:

    >> [Q2, R2] := numeric::factorQR(A, Symbolic)

                   -- +-              -+  +-               -+ --
                   |  |   1/2     1/2  |  |            1/2  |  |
                   |  |  2       2     |  |   1/2  PI 2     |  |
                   |  |  ----, - ----  |  |  2   , -------  |  |
                   |  |   2       2    |  |           2     |  |
                   |  |                |, |                 |  |
                   |  |   1/2    1/2   |  |            1/2  |  |
                   |  |  2      2      |  |        PI 2     |  |
                   |  |  ----,  ----   |  |    0,  -------  |  |
                   |  |   2      2     |  |           2     |  |
                   -- +-              -+  +-               -+ --

For further processing the factors (of domain type `DOM_ARRAY`) are converted to elements of the matrix domain `Dom::Matrix()`:

    >> M := Dom::Matrix():

    >> Q1 := M(Q1): R1 := M(R1): Q2 := M(Q2): R2 := M(R2):

Now the overloaded arithmetical operators `+`, `*`, `^` etc. can be used for further computations:

    >> Q1*R1, Q2*R2

                      +-                      -+  +-       -+
                      |  1.0, -4.33680869e-19  |  |  1,  0  |
                      |                        |, |         |
                      |  1.0,   3.141592654    |  |  1, PI  |
                      +-                      -+  +-       -+

We finally verify the othogonality of the factors `Q1` and `Q2`:

    >> Q1 * M::transpose(Q1), Q2 * M::transpose(Q2)

               +-                                    -+  +-      -+
               |         1.0,       -5.421010863e-20  |  |  1, 0  |
               |                                      |, |        |
               |  -5.421010863e-20,        1.0        |  |  0, 1  |
               +-                                    -+  +-      -+

    >> delete A, Q1, R1, Q2, R2, M:

#### Example 2

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)

              -- +-                       -+                       --
              |  |       0,     1,    0    |                        |
              |  |                         |  +-                -+  |
              |  |                   1/2   |  |   1/2       1/2  |  |
              |  |         1/2      2      |  |  2   , - I 2     |  |
              |  |  1/2 I 2   , 0,  ----   |  |                  |  |
              |  |                   2     |, |    0,      0     |  |
              |  |                         |  |                  |  |
              |  |                    1/2  |  |    0,      0     |  |
              |  |         1/2       2     |  +-                -+  |
              |  |  1/2 I 2   , 0, - ----  |                        |
              |  |                    2    |                        |
              -- +-                       -+                       --

Note that the numerical factorization yields different factors:

    >> numeric::factorQR(A)

          -- +-                                                -+
          |  |         0,       0.7071067812 I, 0.7071067812 I  |
          |  |                                                  |
          |  |  0.7071067812 I,       0.5,           -0.5       |,
          |  |                                                  |
          |  |  0.7071067812 I,      -0.5,            0.5       |
          -- +-                                                -+

             +-                              -+ --
             |  1.414213562, - 1.414213562 I  |  |
             |                                |  |
             |       0,             0         |  |
             |                                |  |
             |       0,             0         |  |
             +-                              -+ --

    >> delete A:

#### Background

- Householder transformations are used to compute the numerical factorization. With the option Symbolic Gram-Schmidt orthonormalization of the columns of A is used.
- For an invertible square matrix A the QR factorization is unique up to 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 non-square matrices the factorization is not unique and the results obtained with/without the option Symbolic may differ (cf. example 2).

#### Changes

- Factorization was extended to non-square matrices.
- The type of the returned matrix factors was changed to `DOM_ARRAY`.

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000