Project

DETERMINATION AND STUDY OF EIGEN VALUE AND SPECTRAL RADIUS BY ITERATIVE METHODS

MAIN CODE:

clear all
close all
clc

A=[5 1 2 ; -3 9 4; 1 2 -7];
B=[10 ;-14; 33];

u = [0 1 2; 0 0 4; 0 0 0];
l = [0 0 0; -3 0 0; 1 2 0];
di = [5 0 0; 0 9 0; 0 0 -7];


mag = [0.25,0.5,0.75,1,1.5,2];


for i = 1 : length(mag)
    
    d = di*mag(i);

%jacobi method  
Tjac = (-inv(d)*(l+u));
Cjac = inv(d)*(B);

%guass seidel 
Tgs = -inv(l+d)*u;
Cgs = inv(d+l)*B;

%succesive relaxation
omega = 0.8;
Tsor = -(inv(d+(omega*l))*((omega*u)+((omega-1)*d)));
Csor = omega*inv(d+(omega*l))*(B);


%finding eigen values
syms lamda
eigen_jac = real(double(solve(det(Tjac - (lamda*eye(3))) == 0,lamda)));
eigen_gs = real(double(solve(det(Tgs - (lamda*eye(3))) == 0,lamda)));
eigen_sor = real(double(solve(det(Tsor - (lamda*eye(3))) == 0,lamda)));


%finding spectral radius for the iterative matrix
spec_jac(i) = max(eigen_jac);
spec_gs(i) = max(eigen_gs);
spec_sor(i) = max(eigen_sor);


%calling function for finding solution
[xjac(:,i),iter_jac(i)] = spectral_function(Tjac,Cjac,B);

[xgs(:,i),iter_gs(i)] = spectral_function(Tgs,Cgs,B);

[xsor(:,i),iter_sor(i)] = spectral_function(Tsor,Csor,B);


end

figure(1)
title('Magnification Vs Spectral radius')
subplot(3,1,1)
plot(mag,spec_jac,'marker','*')
subplot(3,1,2)
plot(mag,spec_gs,'marker','*')
subplot(3,1,3)
plot(mag,spec_gs,'marker','*')

% figure(2)
% title('Magnification Vs Iterations')
% subplot(3,1,1)
% plot(mag,iter_jac,'marker','*')
% subplot(3,1,2)
% plot(mag,iter_gs,'marker','*')
% subplot(3,1,3)
% plot(mag,iter_sor,'marker','*')



function [x,iter] = spectral_function(T,C,B)
  
x = zeros(size(B));
xold = x;
  
error = 100;
tol = 1e-4;
iter = 1;


while (error > tol)
  
x = T*(xold) + C;

error = max(abs(x-xold));
xold = x;

iter = iter+1;
end

end

FUNCTION CODE:

function [output1,output2] = iter_func(A,B,xold)

error = 1e9;
tol = 1e-4;
iter = 0;

    while error > tol
        
        x = A*xold + B;
        error = max(abs(x - xold));
        xold = x;
        iter = iter+1;
        
    end

output1 = x;
output2 = iter;

end

RESULTS:

1. STUDY OF THE PROGRAM:

2. JACOBI METHOD:

3. GUASS SEIDEL METHOD:

4. SOR METHOD:

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.