%% Q11: Test the convergence of Jacobi, Gauss Sediel, and SOR Iterative methods for Linear system Ax=b
% where its coefficient matrix A given as the following :
A=[4 -1 0 0;-1 4 -1 0;0 -1 4 -1;0 0 -1 4]
%% Convert A to be A=L+D+U
[L,D,U]=LDU_M(A);
%% Get the Jacobi and Gauss-Sediel Itartion matrix
T_J=Jacobi_Itr_M(L,D,U)
T_G=Gauss_Sed_Itr_M(L,D,U)
%% Find the the Spectral radius of the three methods
Roh_TJ=Spectral_Radius_M(T_J);
Roh_TG=Spectral_Radius_M(T_G);
W=2/(1+sqrt(1-(Roh_TJ)^2));
% T_W=SOR_Itr_M(L,D,U,W)
% Roh_TW=Spectral_Radius_M(T_W)
Roh_TW=abs(w-1);
%% Test the convergence Condition
if Roh_TJ<1
sprintf('The spectral raduis of Jacobi Iteration Matrix=%0.4g <1',Roh_TJ)
disp('The system "Converge" with Jacobi Iterative method');
else
disp('The system "Not Converge" with Jacobi Iterative method');
end
if Roh_TG<1
sprintf('The spectral raduis of Gauss Sediel Iteration Matrix=%0.4g <1',Roh_TG)
disp('The system "Converge" with Gauss Sediel Iterative method');
else
disp('The system "Not Converge" with Gauss Sediel Iterative method');
end
if Roh_TW<1
sprintf('The spectral raduis of SOR Iteration Matrix=%0.4g <1',Roh_TW)
disp('The system "Converge" with SOR Iterative method');
else
disp('The system "Not Converge" with SOR Iterative method');
end
%% Comapre between these Three methods
if (Roh_TW<Roh_TJ && Roh_TJ<Roh_TG)
disp('Roh_TW < Roh_TJ < Roh_TG');
disp('Then The SOR faster than Jacobi that faster than Gauss-Sed in convergence');
elseif (Roh_TW<Roh_TG && Roh_TG<Roh_TJ)
disp('Roh_TW < Roh_TG < Roh_TJ');
disp('Then The SOR faster than Gauss-Sed that faster than Jacbi in convergence');
elseif (Roh_TJ<Roh_TW && Roh_TW<Roh_TG)
disp('Roh_TJ < Roh_TW < Roh_TG');
disp('Then The Jacobi faster than SOR that faster than Gauss-Sed in convergence');
elseif (Roh_TJ<Roh_TG && Roh_TG<Roh_TW)
disp('Roh_TJ < Roh_TG < Roh_TW');
disp('Then The Jacobi faster than Gauss-Sed that faster than SOR in convergence');
elseif (Roh_TG<Roh_TW && Roh_TW<Roh_TJ)
disp('Roh_TG < Roh_TW < Roh_TJ');
disp('Then The Gauss-Sed faster than SOR that faster than Jacbi in convergence');
elseif (Roh_TG<Roh_TJ && Roh_TJ<Roh_TW)
disp('Roh_TG < Roh_TJ < Roh_TW');
disp('Then The Gauss-Sed faster than Jacbi that faster than SOR in convergence');
end