Technical Tutorials

Blog Post Series of Numerical Analysis 3: Iterative Methods for Large Linear Systems

This is the third blog post of the series on Numerical Analysis. In this post, we will discuss Iterative Methods for Large Linear Systems. The post will cover the theoretical foundations of iterative methods, including matrix splitting...

26 December 2024 · 13 min read

This is the third blog post of the series on Numerical Analysis. In this post, we will discuss Iterative Methods for Large Linear Systems. The post will cover the theoretical foundations of iterative methods, including matrix splitting methods, Jacobi and Gauss-Seidel iterations, and the Conjugate Gradient method. We will also explore the convergence analysis of these methods and their practical implementation in Python. The post will conclude with a discussion of real-world applications and future directions in the field of iterative methods.

Introduction

Why do mathematicians care about iterative methods? The story begins with a fundamental limitation of direct methods. Consider solving a 3D Poisson equation on a 100×100×100100\times 100\times 100 grid. The resulting linear system has one million unknowns. Using Gaussian elimination would require approximately 101810^18 operations - even with a computer performing a trillion operations per second, this would take months. Moreover, storing the full matrix would need 88 terabytes of memory.

This computational barrier isn’t merely an engineering inconvenience - it represents a fundamental mathematical challenge that has driven the development of iterative methods. The beauty of these methods lies in their ability to transform an impossible computation into a tractable one by exploiting the mathematical structure of the problem. Iterative methods are the cornerstone of modern scientific computing, enabling the solution of problems that would otherwise be infeasible.

The mathematical elegance emerges from three key insights:

  1. Many physical problems naturally suggest iteration (think of heat diffusion)
  2. The connection between iteration and polynomial approximation reveals deep theoretical structures
  3. The interplay between matrix properties and convergence behavior leads to rich mathematical theory

Analysis

Mathematical Framework

Matrix Splitting Methods

Consider splitting matrix AA into A=MNA = M - N, where MM is easily invertible. The linear system Ax=bAx = b becomes:

(MN)x=bMx=Nx+bx=M1Nx+M1b\begin{aligned} (M-N)x &= b \\ Mx &= Nx + b \\ x &= M^{-1}Nx + M^{-1}b \end{aligned}

This lead to the following iteration:

xk+1=M1Nxk+M1bx_{k+1} = M^{-1}Nx_{k} + M^{-1}b

Jacobi Method Derivation

For the Jacobi method, we split AA into:

  • DD is the diagonal of AA
  • LL is the strictly lower triangular part of AA
  • UU is the strictly upper triangular part of AA

Such that A=DLUA = D - L - U. The Jacobi iteration is then:

Dx=(L+U)x+bx=D1(L+U)x+D1bDx = (L+U)x + b\\ x = D^{-1}(L+U)x + D^{-1}b

This leads to the Jacobi iteration:

Bj=D1(L+U)xk+1=Bjxk+D1bB_j = D^{-1}(L+U)\\ x_{k+1} = B_jx_{k} + D^{-1}b

The python code for the Jacobi method is as follows:

def jacobi_iteration(A, b, x0, max_iter=1000, tol=1e-6):
    n = len(A)
    x = x0.copy()
    D = np.diag(A)
    R = A - np.diagflat(D)

    for k in range(max_iter):
        x_new = (b - R @ x) / D
        error = np.linalg.norm(x_new - x) / np.linalg.norm(x_new)
        if error < tol:
            return x_new
        x = x_new
    return x

Convergence Analysis

The method converges when the spectral radius of the iteration matrix is less than 11:

ρ(Bj)=maxλΛ(Bj)λ<1\rho(B_j) = \max_{\lambda \in \Lambda(B_j)}|\lambda| < 1

For strictly diagonally dominant matrices, the Jacobi method converges. The spectral radius of the iteration matrix is:

ρ(Bj)=maxi1jiaijaii<1\rho(B_j) = \max_{i} \left|1 - \sum_{j \neq i} \frac{a_{ij}}{a_{ii}}\right| < 1

The convergence rate is linear, with the error bound:

ek+1Bjek\|e_{k+1}\| \leq \|B_j\| \|e_k\|

This theoretical framework explains why Jacobi method converges linearly for diagonally dominant matrices, with each iteration reducing the error by a factor of Bj\|B_j\|.

Conjugate Gradient Method

For symmetric positive definite matrices, the Conjugate Gradient (CG) method is a powerful iterative method.

Derivation from Minimization Principle

For symmetric positive definite AA, solving Ax=bAx = b is equivalent to minimizing the quadratic functional:

f(x)=12xTAxbTxf(x) = \frac{1}{2}x^TAx - b^Tx

where:

  • The gradient is AxbAx - b
  • The Hessian is AA
  • The minimum is at the solution xx
  • The minimization problem is equivalent to solving Ax=bAx = b

The gradient is:

f(x)=Axb=r(x)\nabla f(x) = Ax - b = -r(x)

where r(x)r(x) is the residual. The CG method minimizes f(x)f(x) by iteratively minimizing the residual in conjugate directions.

Conjugate Directions

The CG method constructs orthogonal search directions {pₖ} such that:

piTApj=0forijp_i^TAp_j = 0 \quad \text{for} \quad i \neq j

The iteration proceeds by minimizing the residual in these directions:

xk+1=xk+αkpkx_{k+1} = x_k + \alpha_kp_k

where αk\alpha_k is the step size. The CG method is optimal in the sense that it minimizes the error in the AA-norm.

One may note that αk\alpha_k can be computed as:

αk=rkTrkpkTApk\alpha_k = \frac{r_k^Tr_k}{p_k^TAp_k}

A-Othogonality and Residual Update

The residuals satisfy the A-orthogonality property:

rk+1=rkαkApkr_{k+1} = r_k - \alpha_kAp_k

New search directions are constructed from the residuals:

pk+1=rk+1+βkpkp_{k+1} = r_{k+1} + \beta_kp_k

where βk\beta_k is the conjugacy parameter:

βk=rk+1Trk+1rkTrk\beta_k = \frac{r_{k+1}^Tr_{k+1}}{r_k^Tr_k}

Implementation with Detail Steps

def conjugate_gradient(A, b, x0, tol=1e-10, max_iter=1000):
    """
    Conjugate Gradient method with detailed computation

    Parameters:
    -----------
    A : array_like
        Symmetric positive definite matrix
    b : array_like
        Right-hand side vector
    x0 : array_like
        Initial guess

    Returns:
    --------
    x : array_like
        Solution vector
    history : dict
        Convergence history
    """
    x = x0.copy()
    r = b - A @ x
    p = r.copy()

    # Store convergence history
    history = {
        'residual_norms': [],
        'energy_norms': []
    }

    for k in range(max_iter):
        Ap = A @ p
        rr = r @ r

        # Compute step size
        alpha = rr / (p @ Ap)

        # Update solution and residual
        x += alpha * p
        r_new = r - alpha * Ap

        # Compute convergence metrics
        energy_norm = np.sqrt(x @ (A @ x) - 2*(x @ b))
        history['residual_norms'].append(np.linalg.norm(r))
        history['energy_norms'].append(energy_norm)

        if np.linalg.norm(r_new) < tol:
            return x, history

        # Compute new search direction
        beta = (r_new @ r_new) / rr
        p = r_new + beta * p
        r = r_new

    return x, history

Convergence Analysis

The error in the A-norm satisfies:

ekA2(κ1κ+1)ke0A\|e_k\|_A \leq 2 \left(\frac{\sqrt{\kappa} - 1}{\sqrt{\kappa} + 1}\right)^k \|e_0\|_A

where:

  • κ=λmaxλmin\kappa = \frac{\lambda_{\max}}{\lambda_{\min}} is the condition number
  • The error decreases by a factor of (κ1κ+1)\left(\frac{\sqrt{\kappa} - 1}{\sqrt{\kappa} + 1}\right) at each iteration
  • The CG method converges in at most nn iterations for an n×nn \times n matrix

This leads to the convergence estimate:

k12κln(2ϵ)k \geq \frac{1}{2} \sqrt{\kappa} \ln \left(\frac{2}{\epsilon}\right)

iterations to achieve ekAϵe0A\|e_k\|_A \leq \epsilon \|e_0\|_A.

GMRES Method

Fundamental Principle

The Generalized Minimal Residual (GMRES) method is a powerful iterative method for general linear systems. The method constructs an orthonormal basis of the Krylov subspace:

Kk(A,r0)=span{r0,Ar0,A2r0,,Ak1r0}\mathcal{K}_k(A, r_0) = \text{span}\{r_0, Ar_0, A^2r_0, \ldots, A^{k-1}r_0\}

The GMRES method minimizes the residual over this subspace.

Arnoldi Iteration

The method uses the Arnoldi iteration to construct an orthonormal basis of the Krylov subspace. The Arnoldi iteration constructs the matrix HkH_k such that:

  1. Orthogonalization: hi,j=(Avj,vi)forj<iv^i+1=Avij=1ihi,jvjh_{i,j} = (Av_j, v_i) \quad \text{for} \quad j < i\\ \hat{v}_{i+1} = Av_i - \sum_{j=1}^{i} h_{i,j}v_j
  2. Normalization: hi+1,i=v^i+12vi+1=v^i+1/hi+1,ih_{i+1,i} = \|\hat{v}_{i+1}\|_2\\ v_{i+1} = \hat{v}_{i+1} / h_{i+1,i} where v1=r0/r02v_1 = r_0 / \|r_0\|_2

Minimization Problem

A step nn, GMRES solves:

xn=x0+Vnynx_n = x_0 + V_ny_n

where VnV_n is the Arnoldi basis and yny_n minimizes the residual:

yn=argminyRnr0AVny2y_n = \text{argmin}_{y \in \mathbb{R}^n} \|r_0 - AV_ny\|_2

Implementation

The GMRES method can be implemented as follows:

  1. Construct the Arnoldi basis

     def arnoldi_iteration(A, v, m):
         n = len(v)
         H = np.zeros((m + 1, m))
         V = np.zeros((n, m + 1))
         V[:, 0] = v / np.linalg.norm(v)
    
         for j in range(m):
             w = A @ V[:, j]
             for i in range(j + 1):
                 H[i, j] = np.dot(V[:, i], w)
                 w = w - H[i, j] * V[:, i]
    
             H[j + 1, j] = np.linalg.norm(w)
             if H[j + 1, j] < 1e-12:
                 return V[:, :j+1], H[:j+1, :j]
             V[:, j + 1] = w / H[j + 1, j]
    
         return V, H
  2. Solve the least squares problem

    def gmres(A, b, x0, max_iter, tol):
     r0 = b - A @ x0
     beta = np.linalg.norm(r0)
     v = r0 / beta
    
     H = np.zeros((max_iter + 1, max_iter))
     V = np.zeros((A.shape[0], max_iter + 1))
     V[:, 0] = v
    
     for j in range(max_iter):
         w = A @ V[:, j]
         for i in range(j + 1):
             H[i, j] = w @ V[:, i]
             w = w - H[i, j] * V[:, i]
    
         H[j+1, j] = np.linalg.norm(w)
         if H[j+1, j] < tol:
             break
         V[:, j+1] = w / H[j+1, j]
     return x0 + V[:, :j] @ np.linalg.lstsq(H[:j+1, :j], beta * np.eye(j))[0]

Convergence Analysis

The residual at step kk satisfies:

rk2=minpPkp(A)r02\|r_k\|_2 = \min_{p \in \mathcal{P}_k} \|p(A)r_0\|_2

where Pk\mathcal{P}_k is the set of polynomials of degree at most kk. The GMRES method minimizes the residual over the Krylov subspace, leading to convergence in at most nn iterations for an n×nn \times n matrix.

Theorem

Theorem (Convergence of Iterative Methods)

For the iteration xk+1=Txk+cx_{k+1} = Tx_k + c, convergence occurs if and only if ρ(T)<1\rho(T) < 1, where ρ(T)\rho(T) is the spectral radius of TT.

Proof Let ek=xkxe_k = x_k - x^* be the error at iteration kk. Then:

ek+1=xk+1x=Txk+cx=T(xkx)=Tekek=Tke0e_{k+1} = x_{k+1} - x^* = Tx_k + c - x^* = T(x_k - x^*) = Te_k\\ e_{k} = T^ke_0

By the spectral radius property, ρ(T)<1\rho(T) < 1 implies Tk0\|T^k\| \to 0 as kk \to \infty. This implies that the error ek0e_k \to 0 as kk \to \infty, which is the definition of convergence.

Theorem (CG Convergence Rate)

For the Conjugate Gradient method applied to Ax=bAx = b with AA symmetric positive definite:

xkxA2(κ1κ+1)kx0xA\|x_k - x^*\|_A \leq 2 \left(\frac{\sqrt{\kappa} - 1}{\sqrt{\kappa} + 1}\right)^k \|x_0 - x^*\|_A

where κ=λmaxλmin\kappa = \frac{\lambda_{\max}}{\lambda_{\min}} is the condition number of AA.

Proof(Sketch)

  1. CG minimizes xkxA\|x_k - x^*\|_A over Krylov subspaces of AA.
  2. Error can be expressed as min-max problem over polynomials.
  3. Use Chebyshev polynomial properties to bound error.

Theorem (GMRES Minimization Property)

At step kk, the GMRES approximation xkx_k satisfies:

bAxk2=minxx0+KkbAx2\|b-Ax_k\|_2 = \min_{x \in x_0 + \mathcal{K}_k} \|b - Ax\|_2

where Kk\mathcal{K}_k is the Krylov subspace of AA.

Proof(Sketch)

  1. xk=x0+Vkykx_k = x_0 + V_ky_k minimizes the residual over the Krylov subspace where yky_k minimizes βe1Hky2\|\beta e_1 - H_ky\|_2.
  2. Show that bAxk2=βe1Hkyk2\|b - Ax_k\|_2 = \|\beta e_1 - H_ky_k\|_2.
  3. Demonstrates that this is minimal over x0+Kkx_0 + \mathcal{K}_k.

Theorem (GMRES Convergence)

For non-singular AA, GMRES converges in at most nn steps (in exact arithmetic), where nn is the matrix dimension.

Proof(Sketch)

  1. Show that Kn\mathcal{K}_n contains the solution
  2. Use minimization property
  3. Apply non-singularity of AA to show convergence

Theorem (GMRES Residual Bound)

For normal matrices AA:

rk2minpΠkmaxλσ(A)p(λ)r02\|r_k\|_2 \leq \min_{p \in \Pi_k} \max_{\lambda \in \sigma(A)} |p(\lambda)|\|r_0\|_2

where Πk\Pi_k is the set of polynomials of degree at most kk and σ(A)\sigma(A) is the spectrum of AA.

Proof(Sketch) Uses the fact that for normal matrices:

p(A)2=maxλσ(A)p(λ)\|p(A)\|_2 = \max_{\lambda \in \sigma(A)} |p(\lambda)|

Discussion

Comparison of Methods

Method Selection Framework

MethodMatrix TypeConvergenceComplexityMemoryImplementation
JacobiDiagonally dominantLinearO(n2)O(n^2)O(n)O(n)Simple
CGSymmetric positive definiteκ\sqrt{\kappa}O(n2)O(n^2)O(n)O(n)Complex
GMRESGeneralProblem DependentO(n2)O(n^2)O(n)O(n)Complex

Convergence Behavior

  • Jacobi method converges for diagonally dominant matrices but the convergence rate is slow.
  • CG method converges in at most nn iterations for symmetric positive definite matrices.
  • GMRES method converges in at most nn iterations for general matrices.
  • The CG method is optimal in the AA-norm, while GMRES minimizes the residual over the Krylov subspace, Jacobi method is a simple splitting method.
  • The CG method is optimal for symmetric positive definite matrices, while GMRES is optimal for general matrices, Jacobi method is optimal for diagonally dominant matrices.

Preconditioning Strategies

Classical Preconditioners

  1. Imcomplete LULU (ILUILU) factorization
  2. Sparse Approximate Inverse (SPAISPAI)
  3. Algebraic Multigrid (AMGAMG)

Problem-Specific Preconditioners

For elliptic PDEs:

  • Multigrid preconditioners
def multigrid_preconditioner(A, levels=3):
    """
    Geometric multigrid preconditioner
    """
    def apply_V_cycle(r):
        for l in range(levels):
            smooth(r)
            restrict(r)
        # Coarse grid solve
        for l in range(levels-1, -1, -1):
            prolongate(r)
            smooth(r)
    return apply_V_cycle

Real-World Applications

Computational Fluid Dynamics

Example system:

[ABTB0][up]=[fg]\begin{bmatrix} A & B^T \\ B & 0 \end{bmatrix} \begin{bmatrix} u \\ p \end{bmatrix} = \begin{bmatrix} f \\ g \end{bmatrix}

Structural Analysis

Conclusion

Theoretical Insights

The study of iterative methods reveals a beautiful interplay between linear algebra, functional analysis, and computational mathematics. The progression from simple iterations to sophisticated Krylov subspace methods demonstrates how theoretical insights can lead to practical algorithmic improvements. Key theoretical achievements include:

  1. Understanding convergence through polynomial approximation
  2. Establishing optimality of methods like CG for specific matrix classes
  3. Development of robust error bounds and stopping criteria

Practical Impact

The practical significance of iterative methods cannot be overstated:

  1. Problem Size Scaling
    • Direct methods: O(n3)O(n^3) operations
    • Iterative methods: O(n2)O(n^2) per iteration
    • Memory requirements: O(n)O(n) vs O(n2)O(n^2)
  2. Adaptability to Structure
    • Sparse matrix operations
    • Matrix-free implementations
    • Problem-specific preconditioners

Future Directions

The field continues to evolve along several promising directions:

  1. Algorithmic Improvements
    • Hybrid methods combining different approaches
    • Adaptive parameter selection
    • Auto-tuning frameworks
  2. Hardware Adaptation
    • GPU acceleration
    • Quantum computing integration
    • Mixed precision implementations
  3. Application Domains
    • High-performance computing
    • Machine learning
    • Data assimilation

Final Remarks

The development of iterative methods represents a triumph of mathematical analysis meeting computational practice. As we face increasingly complex computational challenges, the principles established in this field will continue to guide the development of new algorithms and applications. The future lies in adapting these fundamental ideas to emerging computational paradigms while maintaining their mathematical rigor and practical efficiency. This journey through iterative methods demonstrates that the field remains vibrant and essential for modern scientific computing, with many exciting developments yet to come.

Reference

Classical Texts

  • Kincaid, D. and Cheney, W. (2009). Numerical Analysis: Mathematics of Scientific Computing, Third Edition. American Mathematical Society, Pure and Applied Undergraduate Texts, Volume 2.
  • Saad, Y. (2003). Iterative Methods for Sparse Linear Systems, Second Edition. SIAM.
  • Golub, G. H., and Van Loan, C. F. (2013). Matrix Computations, Fourth Edition. Johns Hopkins University Press.

Advanced Topics

  • Trefethen, L. N., and Bau III, D. (1997). Numerical Linear Algebra. SIAM.
  • Hackbusch, W. (2016). Iterative Solution of Large Sparse Systems of Equations, Second Edition. Springer.
  • Greenbaum, A. (1997). Iterative Methods for Solving Linear Systems. SIAM.

Applications and Implementation

  • Davis, T. A. (2006). Direct Methods for Sparse Linear Systems. SIAM.
  • Kelley, C. T. (1995). Iterative Methods for Linear and Nonlinear Equations. SIAM.
  • Saad, Y., and van der Vorst, H. A. (2000). Iterative Solution of Linear Systems in the 20th Century. Journal of Computational and Applied Mathematics.