Exercise: Jacobi and Gauss-Seidel compared

Solving a 4×4 system with Jacobi and with Gauss-Seidel from x⁰=0, comparing how many iterations each needs for the same tolerance.

The system and its solution

System (strictly diagonally dominant, so both converge), with exact solution x*=[1,2,−1,1] and initial guess x⁰=[0,0,0,0]:

10x1x2+2x3=6x1+11x2x3+3x4=252x1x2+10x3x4=113x2x3+8x4=15\begin{aligned} 10x_1-x_2+2x_3&=6\\ -x_1+11x_2-x_3+3x_4&=25\\ 2x_1-x_2+10x_3-x_4&=-11\\ 3x_2-x_3+8x_4&=15 \end{aligned}
ComponentJacobi (k=10)Gauss-Seidel (k=5)Exact
x₁0.99971.00011
x₂2.00042.00002
x₃-1.0004-1.0000-1
x₄1.00061.00001