% converting the coefficient matrix in upper lower and diagonal matrix form
L=[0 0 0;-2 0 0;5 -5 0]
U=[0 2 -2;0 0 1;0 0 0]
D=[3 0 0;0 -2 0; 0 0 4]
% co efficient matrix A
A=L+U+D
% right hand side of the eqn
B=[1 ;-2; -1];
% computing x
x=inv(A)*B;
% introducing new term for sor omega
omega=1
% iteration matrix for jacobi
Tjac=inv(D)*(L+U);
% iteration matrix expansion of jacobi
Sl=[0 0 0;1 0 0;5/4 -5/4 0]
Su=[0 2/3 -2/3;0 0 -1/2; 0 0 1]
Sd=[.7 0 0; 0 0 0; 0 0 0]
% coeficient matrix of jacobi
Tjac=Sl+Su+Sd
% eigen value for jacobi iteration
l=eig(Tjac);
% computing spetral radius jacobi
rho_jac=max(real(eig(Tjac)));
% iteration matrix for gauss_seidel
Tgauss_seidel=inv(L+D)*U
% iteration matrix expansion of gauss seidel
Ml=[0 0 0;0 0 0;0 -5/3 0]
Mu=[0 2/3 -2/3;0 0 1/6;0 0 0]
Md=[ -1 0 0;0 -2/3 0;0 0 1.0416]
% coeficient matrix of gauss_seidel
Tgauss_seidel=Ml+Mu+Md
% eien value gauss seidel iteration
k=eig(Tgauss_seidel)
% computing spetral radius gaus seidel
rho_gauss=max(real(eig(Tgauss_seidel)));
% iterative matrix for s o r
Tsor=(L+(1/omega)*D)*[((1/omega)*D-D-U)]
% eigen value of sor method
n=eig(Tsor)
% computing spetral radius
rho_sor=max(real(eig(Tsor)));