% MATLAB script to experiment with iterative solvers
%
% Written by: Douglas B. Meade
% Created: 19 October 2005

% Define A, b, and initial guess (x0)

A = [ 16 2;2 1];
b = [ 10 -1]';
x0 = zeros(size(b));

% Select the matrix S

S = eye(size(A))
%S = 10*eye(size(A))
%S = diag(diag(A))
%S = diag([8 2])
%S = tril(A)
%S = triu(A)

% Loop to compute next ten iterates

for k=1:10,
   r = b-A*x0;                       % compute residual
   e = S\r;                          % solution to approx residual equation
   x1 = x0+e;                        % compute updated approximate solution
   k, [x0 r e x1]
   disp('Press any key to continue')
   pause                             % hit any key to continue
   x0 = x1;                          % prepare to start next iteration
end
