%
%
%  Within matlab the command
%
%  Iterate(A,b,N,Method,w)
%
%  will implement either Jacobi, Gauss-Seidel or SOR
%  iterative techniques to solve the problem
%
%           A x = b
%
%  The INPUTS are:
%
%           A = nonsingular matrix 
%           b =  any vector (i.e. b=[1;2;3])
%           N = number of iterations requested
%      Method = a string containing the method name:
%                    
%                    Method='jacobi'
%                    Method='gauss'
%                    Method='sor'
%
%           w = relaxation parameter if Method='sor'
%
%  There are few built-in safeguards. If method is not
%  declared as one of the above, Fixed Point iteration
%  is used.The seed value is always x=0.
%
%  The OUTPUT is x. If A is n by n then x is a matrix
%  whose i-th row is the i-th iterate of x.
%
function [x,ELQ]=Iterate(A,b,N,Method,w)
%
%
n=length(b);
%
switch Method
  case('jacobi'),
  Q=diag(diag(A));
  disp('Jacobi Iteration');
  case('gauss'),
  Q=tril(A);
  disp('Gauss Seidel Iteration');
  case('sor'),
  Q=tril(A,-1)+diag(diag(A))/w;
  disp('SOR(w) iteration');
  otherwise
  Q=eye(n,n);
  disp('fixed point')
  end
%
%
K=eye(n,n)-inv(Q)*A;
ELQ=eig(K);
bQ=inv(Q)*b;
%
x=zeros(N,n);
x(1,:)=zeros(1,n);
for i=2:N,
  y=K*x(i-1,:)'+bQ;
  x(i,:)=y';
  end
%
%