# How to obtain the Gauss-Seidel iterative results in this form?

I need to use the Gauss Seidel iterative method to solve the linear equations $$\left\{\begin{array}{l} 8 x_{1}-3 x_{2}+2 x_{3}=20 \\ 4 x_{1}+11 x_{2}-x_{3}=33 \\ 6 x_{1}+3 x_{2}+12 x_{3}=36 \end{array}\right.$$ .

(*GaussSedel iterative method*)

X = {0, 0, 0};
b = {20, 33, 36};
A = ( {
{8, -3, 2},
{4, 11, -1},
{6, 3, 12}
} );
DI = DiagonalMatrix@Diagonal[A];
L = LowerTriangularize[-A, -1];
U = UpperTriangularize[-A, 1];
B = IdentityMatrix - Inverse[DI - L].A;
G = Inverse[DI - L].U
f = Inverse[DI - L].b


But the above code can only get the iteration formula in the form of $$\left(\begin{array}{c} x 1[k+1] \\ x 2[k+1] \\ x 3[k+1] \end{array}\right)=\left(\begin{array}{ccc} 0 & \frac{3}{8} & -\frac{1}{4} \\ 0 & -\frac{3}{22} & \frac{2}{11} \\ 0 & -\frac{27}{176} & \frac{7}{88} \end{array}\right) \cdot\left(\begin{array}{c} x 1[k] \\ x 2[k] \\ x 3[k] \end{array}\right)+f^T$$.

But the reference answer is in the form of (the main difference is that the corner mark k+1 gradually appears in the iteration formula on the right) $$\left\{\begin{array}{l} x_{1}^{(k+1)}=\left(20+3 x_{2}^{(k)}-2 x_{3}^{(k)}\right) / 8 \\ x_{2}^{(k+1)}=\left(33-4 x_{1}^{(k+1)}+x_{3}^{(k)}\right) / 11, \quad k=0,1, \cdots \\ x_{3}^{(k+1)}=\left(36-6 x_{1}^{(k+1)}-3 x_{2}^{(k+1)}\right) / 12 \end{array}\right.$$.

I want to know what I can do to get an iterative formula like the reference answer.

$$\left(\begin{array}{c} x 1[k+1] \\ x 2[k+1] \\ x 3[k+1] \end{array}\right)= \text { MapThread }\left[\text { Dot },\left\{\left(\begin{array}{ccc} 0 & \frac{3}{8} & -\frac{1}{4} \\ -\frac{4}{11} & 0 & \frac{1}{11} \\ -\frac{1}{2} & -\frac{1}{4} & 0 \end{array}\right) ,\left(\begin{array}{ccc} 0 & x 2[k] & x 3[k] \\ x 1[k+1] & 0 & x 3[k+1] \\ x 1[k+1] & x 2[k+1] & \theta \end{array}\right)\right\}\right]+\left(\begin{array}{c} \frac{2 \theta}{8} \\ 3 \\ 3 \end{array}\right)$$

Note: the example used is from page 189 of this book.

• Might find some useful code here. It avoids explicit inverses. – Daniel Lichtblau Sep 16 at 14:53

Based on your data for the matrix $$A$$ and $$b$$, seems like your computation is correct, according to the alternative formulation of Wikipedia,

b = {20, 33, 36};
A = {{8, -3, 2}, {4, 11, -1}, {6, 3, 12}};
L = LowerTriangularize@A;
U = UpperTriangularize[A, 1];
GaussSeidelIter[xv_] := Inverse[L].(b - U.xv);
xv = {Subscript[x, 1], Subscript[x, 2], Subscript[x, 3]};
-Inverse[L].U // Simplify // MatrixForm
GaussSeidelIter@xv // Simplify // MatrixForm


$$\left( \begin{array}{ccc} 0 & \frac{3}{8} & -\frac{1}{4} \\ 0 & -\frac{3}{22} & \frac{2}{11} \\ 0 & -\frac{27}{176} & \frac{7}{88} \\ \end{array} \right)$$

$$\begin{pmatrix} \frac{1}{8} \left(20 + 3 x_2-2 x_3\right) \\ \frac{1}{22} \left(46 -3 x_2+4 x_3\right) \\ \frac{1}{176} \left(216 -27 x_2+14 x_3\right) \end{pmatrix}$$

Its looks like either the refernce solution is faulty or your $$A$$ and $$b$$ do not match the ones used for the reference solution.

• Thank you. Please pay attention to the corner marker k + 1. You will find that this is different from the format I asked for. – A little mouse on the pampas Sep 19 at 4:38
• Thank you. I have given the desired output form in the following answer. – A little mouse on the pampas Sep 20 at 0:49

The approximate results can be obtained according to the formula in the textbook:

n = 3;
b = {20, 33, 36}; a = {{8, -3, 2}, {4, 11, -1}, {6, 3, 12}};
Δx[
i_] := (b[[i]] - Sum[a[[i, j]]*x[j, k + 1], {j, 1, i - 1}] -
Sum[a[[i, j]]*x[j, k], {j, i + 1, n}])/a[[i, i]]
Thread[Table[x[i, k + 1], {i, 1, n}] ==
Table[Δx[i], {i, 1, n}]]