Project

Iterative Solvers for linear systems

Google Drive Link for all sorce code files and functions files

https://drive.google.com/open?id=1UE-_9nn7VMuXmUqr3XWFgwbxaaGaNpdX

Outputs:

1. Jacobi Method

The program also showed the following output in the command window

\"The Jacobi Solver could not converge for the following case for spectral radius 1.020416e+00\"

2. Gauss Siedel Method

The program also showed the following output in the command window

\"The Gauss Siedel Solver could not converge for the following case for spectral radius 1.381472e+00\"

3. Successive Over Relaxation Method

The program ran endlessly when the magnification factor was set to 0.5 as the spectral radius went up to 1.5815 and was unable to converge.

Conclusions and Observations:

We made the following observations:

1. The no. of iterations any solver takes to converge is directly proportional to spectral radius of the iteration matrix i.e. as the spectral radius goes up, the number of iterations neede to converge also goes up.

2. As the Spectral Radius goes above 1, the system becomes unsolvable by iterative solvers.

3. As we increase/magnify the diagonal elements of the coefficient matrix, the spectral radius decreases and vice versa.

%Effect of Diagonal Magnification on spectral radius and number of iterations for various iterative methods


clear all
close all
clc


%Please input the solver to be used
solver=3;
%jacobi=1;gauss sidel=2;SOR=3


%Please Input a system of 3 linear equation in the form of 3x3 matrix
A=[5 1 2; -3 9 4;1 2 -7];
B=[10; -14; 33];
w=1.2 ;   %Over Relaxation Factor
m=[0.5 1 2 3 4 5];   %diagonal magnification

%Direct Solver/Inverting Matrix
X=inv(A)*B;

%AX=B

%Matrix Decomposition
Lo=[0 0 0; A(2,1) 0 0 ; A(3,1) A(3,2) 0];
Up=[0 A(1,2) A(1,3); 0 0 A(2,3); 0 0 0 ];
D=[A(1,1) 0 0 ; 0 A(2,2) 0; 0 0 A(3,3)];






I=eye(3);                         %Identity Matrix
syms f(L);


%Jacobi
if solver ==1
   
    rho_T_jac=zeros(1,length(m));
    iter_jac=zeros(1,length(m));
    
for i=1:length(m)

 A=m(i)*D + Lo + Up;
    
%Iteration Matrix For Jacobi
T_jac= inv(m(i)*D)*(Lo+Up);
    

%Finding Eigen Values for iteration matrix, spectral readius for JACOBI
f(L)=det(T_jac-L*I);              %Characteristic Equation
C=double(coeffs(f,L,\'All\'));      %Coefficient Matrix

eig_T_jac=roots(C);               %Eigen-Values of Iteration Matrix of jacobi method
rho_T_jac(i)=max(abs(eig_T_jac));    %Spectral Radius of Iteration Matrix of jacobi method

[iter_jac(i),x_jac]=jacobi(A,B);


    N=isnan(x_jac);
if max(N)==1
    
    txt=sprintf(\'The Jacobi Solver could not converge for the following case for spectral radius %d\',rho_T_jac(i));
    disp(txt);
    
    
end

end


    subplot(2,1,1);
    plot(m,rho_T_jac);
    xlabel(\'Diagonal Magnification\');
    ylabel(\'Spectral Radius , \\rho\');
    title(\'Effect of Diagonal Magnification on Spectral Radius\');
    
    subplot(2,1,2)
    loglog(rho_T_jac,iter_jac,\'r\');
    xlabel(\'Spectral Radius , \\rho\');
    ylabel(\'No. of Iterations\');
    title(\'Effect of Spectral Radius on No. of Iterations for Jacobi Method\');
    
 
    
   
end


%Gauss Siedel
if solver==2
    
    rho_T_gs=zeros(1,length(m));
    iter_gs=zeros(1,length(i));
    
    
    for i=1:length(m)

 A=m(i)*D + Lo + Up;
    
%Iteration Matrix For gs
T_gs= inv(m(i)*D+Lo)*(Up);
    

%Finding Eigen Values for iteration matrix, spectral readius for GAUSS SIEDEL
f(L)=det(T_gs-L*I);              %Characteristic Equation
C=double(coeffs(f,L,\'All\'));      %Coefficient Matrix

eig_T_gs=roots(C);               %Eigen-Values of Iteration Matrix of gs method
rho_T_gs(i)=max(abs(eig_T_gs));    %Spectral Radius of Iteration Matrix of gs method

[iter_gs(i),x_gs]=gs(A,B);


    N=isnan(x_gs);
if max(N)==1
    
    txt=sprintf(\'The Gauss Siedel Solver could not converge for the following case for spectral radius %d\',rho_T_gs(i));
    disp(txt);
    
    
end

end


    subplot(2,1,1);
    plot(m,rho_T_gs);
    xlabel(\'Diagonal Magnification\');
    ylabel(\'Spectral Radius , \\rho\');
    title(\'Effect of Diagonal Magnification on Spectral Radius\');
    
    subplot(2,1,2)
    loglog(rho_T_gs,iter_gs,\'r\');
    xlabel(\'Spectral Radius , \\rho\');
    ylabel(\'No. of Iterations\');
    title(\'Effect of Spectral Radius on No. of Iterations for Gauss Siedel Method\');
    
    
end



%SOR Method
if solver==3
    
    rho_T_sor=zeros(1,length(m));
    iter_sor=zeros(1,length(i));
    
    
for i=1:length(m)
    
    
     A=m(i)*D + Lo + Up;
  %Iteration Matrix For SOR
T_sor= inv(Lo+m(i)*D)*(Up-(Lo+m(i)*D)*(1-w));
    


%Finding Eigen Values for iteration matrix, spectral readius for SOR
f(L)=det(T_sor-L*I);              %Characteristic Equation
C=double(coeffs(f,L,\'All\'));      %Coefficient Matrix

eig_T_sor=roots(C);               %Eigen-Values of Iteration Matrix of sor method
rho_T_sor(i)=max(abs(eig_T_sor));    %Spectral Radius of Iteration Matrix of sor method

[iter_sor(i),x_sor]=sor(A,B,w);


    N=isnan(x_sor);
if max(N)==1
    
    txt=sprintf(\'The SOR Solver could not converge for the following case for spectral radius %d\',rho_T_sor(i));
    disp(txt);
    
    
end

end


    subplot(2,1,1);
    plot(m,rho_T_sor);
    xlabel(\'Diagonal Magnification\');
    ylabel(\'Spectral Radius , \\rho\');
    title(\'Effect of Diagonal Magnification on Spectral Radius\');
    
    subplot(2,1,2)
    loglog(rho_T_sor,iter_sor,\'r\');
    xlabel(\'Spectral Radius , \\rho\');
    ylabel(\'No. of Iterations\');
    title(\'Effect of Spectral Radius on No. of Iterations for SOR Method\');
    
end


Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.