  function ShowSSORsol()
% Checks out the SOR method on a number of problems

Region = {'S','L','C','D','A','H', 'B'} ; 
GridSize = 20;
close all
for k=1:7
    figure
    AnalyzeThis(Region{k},GridSize)
end
    
  function AnalyzeThis(R,g)
% Displays how omega affects the spectral radius associated with the SOR
% iteration when it is applied to the Laplacian defined by region R and 
% gridsize g. Possible values for R are 'S','L','C','D','A','H', or 'B'
m = 20;
omega = linspace(1,2,m);
rhoSOR = zeros(1,m);
rhoSSOR = zeros(1,m);
G = numgrid(R,g);
subplot(1,2,1)
spy(G)
title('The Region','fontsize',16)
A = delsq(G);
[n,n] = size(A);
L = tril(A,-1);
D = diag(diag(A));
for k=1:20
    M = (D/omega(k) + L);
    N = (1/omega(k)-1)*D-L';
    rhoSOR(k) = max(abs(eig(full(M\N))));
    rhoSSOR(k) = max(abs(eig(full(M'\(N'*(M\N))))));
end
subplot(1,2,2)
plot(omega,rhoSOR,'r',omega,rhoSSOR,'g')
xlabel('omega')
ylabel('spectral radius')
legend('SOR','SSOR')
grid on
set(gcf,'position',[100 100 1400 600])
