Skip to main content

CG algorithm; Gauss-Seidel numerical

Short answer

CG repeats: alpha = r^T r/(d^T A d), x = x + alpha d, r = r - alpha A d, beta = r_new^T r_new/(r^T r), d = r + beta d, until the residual is small. Gauss-Seidel with newest values converges to x1 about 0.62, x2 about -0.76, x3 about 0.03.

Write down the algorithm for the conjugate gradient method. Consider the system

[2−1016−24−38]{x1x2x3}={2−45}\begin{bmatrix} 2 & -1 & 0 \\ 1 & 6 & -2 \\ 4 & -3 & 8 \end{bmatrix}\begin{Bmatrix} x_1 \\ x_2 \\ x_3 \end{Bmatrix} = \begin{Bmatrix} 2 \\ -4 \\ 5 \end{Bmatrix}

Solve the above system by using Gauss-Seidel iteration starting with x(0)=(0,0,0)Tx^{(0)} = (0, 0, 0)^T.

Algorithm for the conjugate gradient method

  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.

The method needs a symmetric positive definite matrix and gives the exact solution in at most nn steps.

Gauss-Seidel solution

The matrix is diagonally dominant (2>12>1, 6>36>3, 8>78>7), so Gauss-Seidel converges. Rewrite the equations:

x1=2+x22,x2=−4−x1+2x36,x3=5−4x1+3x28x_1=\frac{2+x_2}{2},\qquad x_2=\frac{-4-x_1+2x_3}{6},\qquad x_3=\frac{5-4x_1+3x_2}{8}

Start with x(0)=(0,0,0)x^{(0)}=(0,0,0) and use the newest values at once.

Iterationx1x_1x2x_2x3x_3
11.0000-0.8333-0.1875
20.5833-0.82640.0234
30.5868-0.75670.0479
40.6217-0.75430.0313
50.6228-0.76000.0286
60.6200-0.76050.0298
70.6198-0.76000.0301
80.6200-0.76000.0300

Example of iteration 1: x1=(2+0)/2=1x_1=(2+0)/2=1; x2=(−4−1+0)/6=−0.8333x_2=(-4-1+0)/6=-0.8333; x3=(5−4+3(−0.8333))/8=−0.1875x_3=(5-4+3(-0.8333))/8=-0.1875.

Answer: x1≈0.62, x2≈−0.76, x3≈0.03x_1\approx0.62,\ x_2\approx-0.76,\ x_3\approx0.03.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computational Techniques in Civil Engineering chapter 2 questions →