MATH 372 -- Numerical Linear Algebra Jacobi Iteration Example April 11, 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 % The diagonal entries in A form the diagonal % matrix D; the Rest is L + U >> D = [4 0 0; 0 5 0; 0 0 3] D = 4 0 0 0 5 0 0 0 3 >> Rest = A - D Rest = 0 1 2 3 0 1 1 1 0 % Jacoby iteration in matrix form is the % iteration scheme x^(k+1) = D^(-1)(-(L+U)x^(k) + b) ID = inv(D); for i = 1:20 x = -ID*Rest*x + ID*b end % after 5th iteration: x = 0.3303 -0.1669 -0.0364 % after 10th iteration x = 0.3156 -0.1846 -0.0479 % after 15th iteration x = 0.3187 -0.1812 -0.0449 % after 20th iteration x = 0.3181 -0.1819 -0.0456 % MATLAB's solution: >> A \ b ans = 0.3182 -0.1818 -0.0455