Skip to main content

Conjugate gradient numerical (2,-1 system)

Short answer

Starting from x0=0, compute residuals, step lengths, and direction updates. After three iterations, the exact solution is x1=3, x2=2, x3=1.

Solve the given system of equations using the conjugate gradient method.

2x1−x2=42x_1 - x_2 = 4

−x1+2x2−x3=0-x_1 + 2x_2 - x_3 = 0

−x2+2x3=0-x_2 + 2x_3 = 0

Matrix form: A=[2−10−12−10−12]A=\begin{bmatrix}2&-1&0\\-1&2&-1\\0&-1&2\end{bmatrix}, b={4,0,0}Tb=\{4,0,0\}^T. AA is symmetric and positive definite. Start with x0={0,0,0}Tx_0=\{0,0,0\}^T.

r0=b−Ax0={4,0,0}Tr_0=b-Ax_0=\{4,0,0\}^T, d0=r0d_0=r_0.

Iteration 1

Ad0={8,−4,0}Tα0=r0Tr0d0TAd0=1632=0.5x1={2,0,0}Tr1=r0−α0Ad0={0,2,0}Tβ0=416=0.25,d1=r1+β0d0={1,2,0}T\begin{aligned} Ad_0&=\{8,-4,0\}^T\\ \alpha_0&=\frac{r_0^Tr_0}{d_0^TAd_0}=\frac{16}{32}=0.5\\ x_1&=\{2,0,0\}^T\\ r_1&=r_0-\alpha_0Ad_0=\{0,2,0\}^T\\ \beta_0&=\frac{4}{16}=0.25,\quad d_1=r_1+\beta_0d_0=\{1,2,0\}^T \end{aligned}

Iteration 2

Ad1={0,3,−2}Tα1=46=0.6667x2={2.6667, 1.3333, 0}Tr2={0,0,1.3333}Tβ1=1.77784=0.4444,d2={0.4444, 0.8889, 1.3333}T\begin{aligned} Ad_1&=\{0,3,-2\}^T\\ \alpha_1&=\frac{4}{6}=0.6667\\ x_2&=\{2.6667,\,1.3333,\,0\}^T\\ r_2&=\{0,0,1.3333\}^T\\ \beta_1&=\frac{1.7778}{4}=0.4444,\quad d_2=\{0.4444,\,0.8889,\,1.3333\}^T \end{aligned}

Iteration 3

Ad2={0,0,1.7778}Tα2=1.77782.3704=0.75x3={3, 2, 1}Tr3={0,0,0}T\begin{aligned} Ad_2&=\{0,0,1.7778\}^T\\ \alpha_2&=\frac{1.7778}{2.3704}=0.75\\ x_3&=\{3,\,2,\,1\}^T\\ r_3&=\{0,0,0\}^T \end{aligned}

The residual is zero after n=3n=3 iterations, as expected for CG.

Answer: x1=3, x2=2, x3=1x_1=3,\ x_2=2,\ x_3=1. (Check: 2(3)−2=42(3)-2=4, −3+4−1=0-3+4-1=0, −2+2=0-2+2=0.)

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computational Techniques in Civil Engineering chapter 2 questions →