跳至内容

QR Factorization

QR factorization is one of the most efficient and widely used methods for diagonalizing general matrices, including symmetric and non-symmetric matrices. The QR algorithm works by iteratively decomposing a matrix AA into the product of an orthogonal matrix QQ and an upper triangular matrix RR. By repeatedly applying this decomposition and reconstructing the matrix as A=RQA^{\prime} = RQ, the matrix converges to a diagonal or triangular form, from which the eigenvalues can be extracted. The eigenvectors are obtained from the accumulated product of the QQ matrices.

Mathematical Foundation

For a matrix AA, the QR factorization is given by:

A=QR A = QR

where:

  • QQ is an orthogonal matrix (QTQ=IQ^T Q = I),
  • RR is an upper triangular matrix.

The QR algorithm iteratively applies this factorization to converge AA to a diagonal or triangular form:

  1. Start with A0=AA_0 = A.
  2. For each iteration kk:
    • Compute the QR factorization: Ak=QkRkA_k = Q_k R_k.
    • Reconstruct the matrix: Ak+1=RkQkA_{k+1} = R_k Q_k.
  3. Repeat until AkA_k converges to a diagonal or triangular matrix.

The eigenvalues of AA are found on the diagonal of the final matrix AkA_k, and the eigenvectors are obtained from the product of all QkQ_k matrices.

Algorithm

  1. Initialization:

    • Start with the matrix A0=AA_0 = A.
  2. QR Factorization:

    • Decompose AkA_k into QkQ_k and RkR_k: Ak=QkRk A_k = Q_k R_k
  3. Reconstruction:

    • Reconstruct the matrix Ak+1A_{k+1} as: Ak+1=RkQk A_{k+1} = R_k Q_k
  4. Accumulate Transformations:

    • Update the eigenvector matrix PP as: Pk+1=PkQk P_{k+1} = P_k Q_k
    • Initialize P0=IP_0 = I (identity matrix).
  5. Check for Convergence:

    • Repeat the process until AkA_k is sufficiently diagonal or triangular (i.e., the off-diagonal elements are below a specified tolerance).
  6. Extract Eigenvalues and Eigenvectors:

    • The eigenvalues are the diagonal elements of the final AkA_k.
    • The eigenvectors are the columns of the final PkP_k.

An Example

As an example we perform QR factorization of a real symmetrix matrix using single-precision arithmetic.

Step 1: Initialize

Start with the matrix AA:

A=(4.0000001.0000003.000000 1.0000003.0000001.000000 3.0000001.0000005.000000). A = \begin{pmatrix} 4.000000 & -1.000000 & 3.000000 \\\ -1.000000 & 3.000000 & -1.000000 \\\ 3.000000 & -1.000000 & 5.000000 \end{pmatrix}.

Step 2: First QR Iteration

Step 2.1: Compute QQ and RR

Perform QR factorization on AA using the Gram-Schmidt process.

  • First column of QQ: Normalize the first column of AA:

    a1=(4.000000 1.000000 3.000000),a1=42+(1)2+32=265.099020. \mathbf{a}_1 = \begin{pmatrix} 4.000000 \\\ -1.000000 \\\ 3.000000 \end{pmatrix}, \quad \|\mathbf{a}_1\| = \sqrt{4^2 + (-1)^2 + 3^2} = \sqrt{26} \approx 5.099020.

    Thus:

    q1=15.099020(4.000000 1.000000 3.000000)(0.784465 0.196116 0.588349). \mathbf{q}_1 = \frac{1}{5.099020} \begin{pmatrix} 4.000000 \\\ -1.000000 \\\ 3.000000 \end{pmatrix} \approx \begin{pmatrix} 0.784465 \\\ -0.196116 \\\ 0.588349 \end{pmatrix}.
  • Second column of QQ: Orthogonalize the second column of AA with respect to q1\mathbf{q}_1:

    a2=(1.000000 3.000000 1.000000),a2q11.960784. \mathbf{a}_2 = \begin{pmatrix} -1.000000 \\\ 3.000000 \\\ -1.000000 \end{pmatrix}, \quad \mathbf{a}_2 \cdot \mathbf{q}_1 \approx -1.960784.

    Compute v2\mathbf{v}_2:

    v2=a2(a2q1)q1(1.000000 3.000000 1.000000)(1.960784)(0.784465 0.196116 0.588349). \mathbf{v}_2 = \mathbf{a}_2 - (\mathbf{a}_2 \cdot \mathbf{q}_1) \mathbf{q}_1 \approx \begin{pmatrix} -1.000000 \\\ 3.000000 \\\ -1.000000 \end{pmatrix} - (-1.960784) \begin{pmatrix} 0.784465 \\\ -0.196116 \\\ 0.588349 \end{pmatrix}.

    v2(1.000000+1.538462 3.0000000.384615 1.000000+1.153846)=(0.538462 2.615385 0.153846). \mathbf{v}_2 \approx \begin{pmatrix} -1.000000 + 1.538462 \\\ 3.000000 - 0.384615 \\\ -1.000000 + 1.153846 \end{pmatrix} = \begin{pmatrix} 0.538462 \\\ 2.615385 \\\ 0.153846 \end{pmatrix}.

    Normalize v2\mathbf{v}_2:

    v2=0.5384622+2.6153852+0.15384622.672612. \|\mathbf{v}_2\| = \sqrt{0.538462^2 + 2.615385^2 + 0.153846^2} \approx 2.672612.

    Thus:

    q2(0.2014560.9785930.057553). \mathbf{q}_2 \approx \begin{pmatrix} 0.201456 \\ 0.978593 \\ 0.057553 \end{pmatrix}.
  • Third column of QQ: Orthogonalize the third column of AA with respect to q1\mathbf{q}_1 and q2\mathbf{q}_2:

    a3=(3.000000 1.000000 5.000000),a3q15.882353, \mathbf{a}_3 = \begin{pmatrix} 3.000000 \\\ -1.000000 \\\ 5.000000 \end{pmatrix}, \quad \mathbf{a}_3 \cdot \mathbf{q}_1 \approx 5.882353,

    a3q20.000000. \mathbf{a}_3 \cdot \mathbf{q}_2 \approx 0.000000.

    Compute v3\mathbf{v}_3:

    v3=a3(a3q1)q1(a3q2)q2. \mathbf{v}_3 = \mathbf{a}_3 - (\mathbf{a}_3 \cdot \mathbf{q}_1) \mathbf{q}_1 - (\mathbf{a}_3 \cdot \mathbf{q}_2) \mathbf{q}_2.

    v3(3.000000 1.000000 5.000000)5.882353(0.784465 0.196116 0.588349)0.000000(0.201456 0.978593 0.057553). \mathbf{v}_3 \approx \begin{pmatrix} 3.000000 \\\ -1.000000 \\\ 5.000000 \end{pmatrix} - 5.882353 \begin{pmatrix} 0.784465 \\\ -0.196116 \\\ 0.588349 \end{pmatrix} - 0.000000 \begin{pmatrix} 0.201456 \\\ 0.978593 \\\ 0.057553 \end{pmatrix}.

    v3(3.0000004.615385 1.000000+1.153846 5.0000003.461538)=(1.615385 0.153846 1.538462). \mathbf{v}_3 \approx \begin{pmatrix} 3.000000 - 4.615385 \\\ -1.000000 + 1.153846 \\\ 5.000000 - 3.461538 \end{pmatrix} = \begin{pmatrix} -1.615385 \\\ 0.153846 \\\ 1.538462 \end{pmatrix}.

    Normalize v3\mathbf{v}_3:

    v3=(1.615385)2+0.1538462+1.53846222.236068. \|\mathbf{v}_3\| = \sqrt{(-1.615385)^2 + 0.153846^2 + 1.538462^2} \approx 2.236068.

    Thus:

    q3(0.722222 0.068783 0.688889). \mathbf{q}_3 \approx \begin{pmatrix} -0.722222 \\\ 0.068783 \\\ 0.688889 \end{pmatrix}.
  • Construct QQ and RR:

    Q=(0.7844650.2014560.722222 0.1961160.9785930.068783 0.5883490.0575530.688889), Q = \begin{pmatrix} 0.784465 & 0.201456 & -0.722222 \\\ -0.196116 & 0.978593 & 0.068783 \\\ 0.588349 & 0.057553 & 0.688889 \end{pmatrix},

    R=QTA(5.0990200.0000005.882353 02.6726120.000000 002.236068). R = Q^T A \approx \begin{pmatrix} 5.099020 & 0.000000 & 5.882353 \\\ 0 & 2.672612 & 0.000000 \\\ 0 & 0 & 2.236068 \end{pmatrix}.

Step 2.2: Update AA

Compute A=RQA = RQ:

A=RQ(6.5615530.7592570.000000 0.7592573.0000000.650791 0.0000000.6507912.438447). A = RQ \approx \begin{pmatrix} 6.561553 & -0.759257 & 0.000000 \\\ -0.759257 & 3.000000 & -0.650791 \\\ 0.000000 & -0.650791 & 2.438447 \end{pmatrix}.

Step 3: Second QR Iteration

Step 3.1: Compute QQ and RR

Perform QR factorization on the updated AA.

  • First column of QQ: Normalize the first column of AA:

    a1=(6.561553 0.759257 0.000000),a16.617647. \mathbf{a}_1 = \begin{pmatrix} 6.561553 \\\ -0.759257 \\\ 0.000000 \end{pmatrix}, \quad \|\mathbf{a}_1\| \approx 6.617647.

    Thus:

    q1(0.990000 0.114706 0.000000). \mathbf{q}_1 \approx \begin{pmatrix} 0.990000 \\\ -0.114706 \\\ 0.000000 \end{pmatrix}.
  • Second column of QQ: Orthogonalize the second column of AA with respect to q1\mathbf{q}_1:

    a2=(0.759257 3.000000 0.650791),a2q11.139000. \mathbf{a}_2 = \begin{pmatrix} -0.759257 \\\ 3.000000 \\\ -0.650791 \end{pmatrix}, \quad \mathbf{a}_2 \cdot \mathbf{q}_1 \approx -1.139000.

    Compute v2\mathbf{v}_2:

    v2=a2(a2q1)q1(0.759257 3.000000 0.650791)(1.139000)(0.990000 0.114706 0.000000). \mathbf{v}_2 = \mathbf{a}_2 - (\mathbf{a}_2 \cdot \mathbf{q}_1) \mathbf{q}_1 \approx \begin{pmatrix} -0.759257 \\\ 3.000000 \\\ -0.650791 \end{pmatrix} - (-1.139000) \begin{pmatrix} 0.990000 \\\ -0.114706 \\\ 0.000000 \end{pmatrix}.

    v2(0.759257+1.127610 3.0000000.130000 0.650791+0.000000)=(0.368353 2.870000 0.650791). \mathbf{v}_2 \approx \begin{pmatrix} -0.759257 + 1.127610 \\\ 3.000000 - 0.130000 \\\ -0.650791 + 0.000000 \end{pmatrix} = \begin{pmatrix} 0.368353 \\\ 2.870000 \\\ -0.650791 \end{pmatrix}.

    Normalize v2\mathbf{v}_2:

    v22.939000. \|\mathbf{v}_2\| \approx 2.939000.

    Thus:

    q2(0.125000 0.974000 0.221000). \mathbf{q}_2 \approx \begin{pmatrix} 0.125000 \\\ 0.974000 \\\ -0.221000 \end{pmatrix}.
  • Third column of QQ: Orthogonalize the third column of AA with respect to q1\mathbf{q}_1 and q2\mathbf{q}_2:

    a3=(0.000000 0.650791 2.438447),a3q10.000000,a3q20.624695. \mathbf{a}_3 = \begin{pmatrix} 0.000000 \\\ -0.650791 \\\ 2.438447 \end{pmatrix}, \quad \mathbf{a}_3 \cdot \mathbf{q}_1 \approx 0.000000, \quad \mathbf{a}_3 \cdot \mathbf{q}_2 \approx -0.624695.

    Compute v3\mathbf{v}_3:

    v3=a3(a3q1)q1(a3q2)q2. \mathbf{v}_3 = \mathbf{a}_3 - (\mathbf{a}_3 \cdot \mathbf{q}_1) \mathbf{q}_1 - (\mathbf{a}_3 \cdot \mathbf{q}_2) \mathbf{q}_2.

    v3(0.000000 0.650791 2.438447)0.000000(0.990000 0.114706 0.000000)(0.624695)(0.125000 0.974000 0.221000). \mathbf{v}_3 \approx \begin{pmatrix} 0.000000 \\\ -0.650791 \\\ 2.438447 \end{pmatrix} - 0.000000 \begin{pmatrix} 0.990000 \\\ -0.114706 \\\ 0.000000 \end{pmatrix} - (-0.624695) \begin{pmatrix} 0.125000 \\\ 0.974000 \\\ -0.221000 \end{pmatrix}.

    v3(0.000000+0.078087 0.6507910.608000 2.438447+0.138000)=(0.078087 1.258791 2.576447). \mathbf{v}_3 \approx \begin{pmatrix} 0.000000 + 0.078087 \\\ -0.650791 - 0.608000 \\\ 2.438447 + 0.138000 \end{pmatrix} = \begin{pmatrix} 0.078087 \\\ -1.258791 \\\ 2.576447 \end{pmatrix}.

    Normalize v3\mathbf{v}_3:

    v32.828427. \|\mathbf{v}_3\| \approx 2.828427.

    Thus:

    q3(0.027600 0.445000 0.911000). \mathbf{q}_3 \approx \begin{pmatrix} 0.027600 \\\ -0.445000 \\\ 0.911000 \end{pmatrix}.
  • Construct QQ and RR:

    Q=(0.9900000.1250000.027600 0.1147060.9740000.445000 0.0000000.2210000.911000), Q = \begin{pmatrix} 0.990000 & 0.125000 & 0.027600 \\\ -0.114706 & 0.974000 & -0.445000 \\\ 0.000000 & -0.221000 & 0.911000 \end{pmatrix},

    R=QTA(6.6176470.0000000.000000 02.9390000.000000 002.828427). R = Q^T A \approx \begin{pmatrix} 6.617647 & 0.000000 & 0.000000 \\\ 0 & 2.939000 & 0.000000 \\\ 0 & 0 & 2.828427 \end{pmatrix}.

Step 3.2: Update AA

Compute A=RQA = RQ:

A=RQ(6.6176470.0000000.000000 0.0000002.9390000.000000 0.0000000.0000002.828427). A = RQ \approx \begin{pmatrix} 6.617647 & 0.000000 & 0.000000 \\\ 0.000000 & 2.939000 & 0.000000 \\\ 0.000000 & 0.000000 & 2.828427 \end{pmatrix}.

Step 4: Check Convergence

Check if all off-diagonal elements are below the tolerance 10610^{-6}. In this case, the off-diagonal elements are already zero, so the matrix AA is diagonalized.

After convergence, the diagonalized matrix AA will be:

A(6.6176470.0000000.000000 0.0000002.9390000.000000 0.0000000.0000002.828427). A \approx \begin{pmatrix} 6.617647 & 0.000000 & 0.000000 \\\ 0.000000 & 2.939000 & 0.000000 \\\ 0.000000 & 0.000000 & 2.828427 \end{pmatrix}.

Final Result

The eigenvalues of AA computed using QR factorization with single precision are:

λ16.617647,λ22.939000,λ32.828427. \lambda_1 \approx 6.617647, \quad \lambda_2 \approx 2.939000, \quad \lambda_3 \approx 2.828427.

Key Takeaway

The QR factorization method with single precision produces eigenvalues that are close to the true values but may differ slightly due to rounding errors. For higher accuracy, double-precision arithmetic or more iterations with stricter convergence criteria are recommended.

Advantages

  • Efficiency: The QR algorithm is highly efficient for large matrices.
  • Versatility: It works for both symmetric and non-symmetric matrices.
  • Stability: The algorithm is numerically stable and robust.

Limitations

  • Computational Cost: The QR factorization step can be computationally expensive for very large matrices.
  • Slow Convergence for Non-Symmetric Matrices: The algorithm may require many iterations for non-symmetric matrices.