% 4-7-2008 % Jacobi's Method clear all; close all; % Settings TOLERANCE = 10^(-6); max_iterations = 1000; % Initial guess x(1)=1; y(1)=2; z(1)=2; for i=2:max_iterations % Convergent iteration scheme x(i) = (7 + y(i-1) - z(i-1))/4; y(i) = (21 + 4*x(i-1) + z(i-1))/8; z(i) = (15 + 2 * x(i-1) - y(i-1)) / 5; % Check to see if we have converged, look up 'help norm' to find out % what it does. if ( norm([x(i) y(i) z(i)]-[x(i-1) y(i-1) z(i-1)],2) < TOLERANCE ) break; end end % Plot convergence plot(x,'o-') hold on plot(y,'ro-') plot(z,'ko-') axis([1 i 0 4.1]) legend('x','y','z') title('Convergence of Jacobi Method') xlabel('Iteration'); ylabel('Value of (x y z)');