Skip to main content

Conjugate gradient method and algorithm

Short answer

Conjugate gradient solves symmetric positive definite systems by minimising energy along A-conjugate directions, converging in at most n steps. Algorithm: set initial residual r0=b-Ax0, direction d0=r0; for each step compute alpha=(r_k^T r_k)/(d_k^T A d_k), update x and r, then beta=(r_{k+1}^T r_{k+1})/(r_k^T r_k) to update direction.

Explain the conjugate gradient method and its algorithm for solving a system of linear equations.

Conjugate gradient method

The conjugate gradient (CG) method solves Ax=bAx = b for a symmetric, positive definite matrix AA. It is equivalent to minimising the quadratic energy

Π(x)=12xTAx−bTx\Pi(x) = \tfrac{1}{2}x^T A x - b^T x

whose minimum is exactly the solution of Ax=bAx=b. The minimum is searched along directions dkd_k that are A-conjugate, i.e. diTAdj=0d_i^T A d_j = 0 for i≠ji \ne j. Each step minimises Π\Pi along one direction without spoiling the earlier ones, so in exact arithmetic the solution is reached in at most nn steps for an n×nn \times n system. The residual r=b−Axr = b - Ax is the negative gradient of Π\Pi.

Compared with direct elimination, CG needs only matrix-vector products, so it stores only the non-zero terms of AA. It is good for large sparse systems, and rounding errors do not accumulate in a long elimination.

Algorithm

  1. Choose a starting vector x0x_0 (usually 00). Compute the residual r0=b−Ax0r_0 = b - Ax_0 and set the first search direction d0=r0d_0 = r_0.
  2. For k=0,1,2,…k = 0, 1, 2, \dots repeat:
    • Step length: αk=rkTrkdkTAdk\alpha_k = \dfrac{r_k^T r_k}{d_k^T A d_k}
    • Update the solution: xk+1=xk+αkdkx_{k+1} = x_k + \alpha_k d_k
    • Update the residual: rk+1=rk−αkAdkr_{k+1} = r_k - \alpha_k A d_k
    • Check convergence: stop if ∥rk+1∥<\|r_{k+1}\| < tolerance.
    • Direction factor: βk=rk+1Trk+1rkTrk\beta_k = \dfrac{r_{k+1}^T r_{k+1}}{r_k^T r_k}
    • New direction: dk+1=rk+1+βkdkd_{k+1} = r_{k+1} + \beta_k d_k
  3. The last xk+1x_{k+1} is the solution.

Convergence is faster if AA has clustered eigenvalues, and preconditioning is used to improve this.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computational Techniques in Civil Engineering chapter 2 questions →