MATH 372 -- Numerical Linear Algebra Gauss-Seidel Iteration Example April 13, 2007 % We wish to solve the linear system % Ax = b for coefficient matrix and % right-hand side vector A, b as follows: >> A = [4 1 2; 3 5 1; 1 1 3] A = 4 1 2 3 5 1 1 1 3 >> b = [1; 0; 0] b = 1 0 0 >> DPlusL=[4 0 0; 3 5 0; 1 1 3] DPlusL = 4 0 0 3 5 0 1 1 3 >> DLI=inv(DPlusL) DLI = 0.2500 0 0 -0.1500 0.2000 0 -0.0333 -0.0667 0.3333 >> x = [0; 0; 0] x = 0 0 0 >> for i = 1:7 end >> U = A - DPlusL U = 0 1 2 0 0 1 0 0 0 >> for i=1:10 x = -DLI*U*x + DLI*b end x = 0.2500 -0.1500 -0.0333 x = 0.3042 -0.1758 -0.0428 x = 0.3153 -0.1807 -0.0449 x = 0.3176 -0.1816 -0.0453 x = 0.3181 -0.1818 -0.0454 x = 0.3182 -0.1818 -0.0454 x = 0.3182 -0.1818 -0.0455 % MATLAB's solution: >> A \ b ans = 0.3182 -0.1818 -0.0455 % Note: agreement to at least 4 decimal places after % only 7 iterations versus more than 20 for Jacobi % to achieve this level of accuracy.