You are on page 1of 13

GAUSS SIEDEL LINEAR SOLVER

MATLAB PROGRAM :
function [ x ] = itergauss( A,b,n )
%%check if gauss-seidel method is
applicable
[si,sj]=size(A);
if si~=sj
disp('error matrix is not square');
return
end
if prod(diag(A))==0
disp('gauss-seidel iterative method is
not applicable');
return
end
E=tril(A,-1);
F=triu(A,1);
D=A-E-F
Bj=-inv(D)*(E+F);
rho=max(abs(eig(Bj))); %spectral radius
if rho>=1
rho=1;
end
%if rho>=1
% disp('gauss-seidel method do not
converge');
% return
%end
y=zeros(si,n);
tic

0000 4.0000 0 0 10.0000 4.0000 8.0 0 10 4 30 54 2 0 0.0000 60.0 2 45 5 38 10 0 0 0.0000 5.0 0 8 4 50 37 0 1 0.0000 45.for i=[1:1:n] y(:.0000 30.5 5.0 0 1 1 22 14 7 0 55] A= Columns 1 through 5 52.0000 0 0 6.0 0 6 6 60 26 0 2 0 .0000 0 0 8. end x=y(:. >> A=[52 19 11 3 8 1 0 0.0000 50.0000 16.8000 2.n).0000 75.0000 38.2 0.0000 0 1.0 1 16 2 50 30 1 0 0 .0000 50.0 0 6 2 20 70 0 2 0.8 2 75 10 0 0.i+1)=inv(D+E)*(b-F*y(:.0000 .0000 11. execution_time=toc end MATLAB RESULTS …….0000 2.i)).0000 0 1.0000 19.5.0000 11.0000 6.0 1 11.0000 0 2.0000 3.

0.6400 6. 0 0 6.0000 0 0.0000 0 0.0000 >> b=[6.0000 7.0000 0 55.6.0000 0 0 0 26.64.0000 0 30.0000 0 0 70.10.0000 20.3.8000 3.16.2000 0 10.0000 1.5600 >> n=9 .0000 22.2.72 .0000 0 14.5.8.1200 5.0000 0 2.0000 1.5000 10.0400 2.1600 1.0000 0 0 37.1.5000 5.8.56] b= 6.3600 0.0000 2.0000 Columns 6 through 9 1.5.0000 0 1.8000 10.0000 0 0 1.7200 5.04.36.12.0000 0 54.0000 0 2.0000 2.

n= 9 >> [x]=itergauss(A.b.n) Undefined function or variable 'itergauss'. >> [x]=itergauss(A.n) D= Columns 1 through 8 52 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 45 0 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 50 0 0 0 0 0 0 0 0 37 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 Column 9 0 0 0 0 .b.

n) D= Columns 1 through 8 52 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 45 0 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 50 0 0 0 0 0 0 0 0 37 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 2 .b. 0 0 0 0 55 gauss-seidel method do not converge Output argument "x" (and maybe others) not assigned during call to "itergauss".sj]=size(A). >> [x]=itergauss(A. >> itergauss Not enough input arguments. Error in itergauss (line 4) [si.

>> [x]=itergauss(A.n) D= Columns 1 through 8 52 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 45 0 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 50 0 0 0 0 0 0 0 0 37 0 0 .b. 0 0 0 0 0 0 0 0 Column 9 0 0 0 0 0 0 0 0 55 gauss-seidel method do not converge Output argument "x" (and maybe others) not assigned during call to "itergauss".

0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 Column 9 0 0 0 0 0 0 0 0 55 gauss-seidel method do not converge Output argument "x" (and maybe others) not assigned during call to "itergauss".b. >> x=itergauss(A.n) D= Columns 1 through 8 52 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 45 0 0 0 0 0 0 0 0 6 0 0 0 0 .

>> itergauss(A. 0 0 0 0 50 0 0 0 0 0 0 0 0 37 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 Column 9 0 0 0 0 0 0 0 0 55 gauss-seidel method do not converge Output argument "x" (and maybe others) not assigned during call to "itergauss".n) D= Columns 1 through 8 52 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 .b.

0 0 45 0 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 50 0 0 0 0 0 0 0 0 37 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 Column 9 0 0 0 0 0 0 0 0 55 RESULTS AFTER TWEAKING THE PROGRAM . x=itergauss(A.b.n) D= Columns 1 through 8 52 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 ..

6877 51.1768 . 0 0 45 0 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 50 0 0 0 0 0 0 0 0 37 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 Column 9 0 0 0 0 0 0 0 0 55 execution_time = 0.0122 x= -17.

0.0.9545.9454 0.9182 >> x=itergauss(A.9825.9545 0.0614 -0.9629.9732 0.8991 0.0.9732.8991.9182] b1 = 0.0.0.0.1746 >> b1=[0.n) D= Columns 1 through 8 52 0 0 0 0 0 0 0 .9825 0.0.9167.9454.0558 12.7946 0. -3.9951 2.5444 0.9629 0.7946.b1.9167 0.9662 -19.6921 -17.0.

4070 . 0 1 0 0 0 0 0 0 0 0 45 0 0 0 0 0 0 0 0 6 0 0 0 0 0 0 0 0 50 0 0 0 0 0 0 0 0 37 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 Column 9 0 0 0 0 0 0 0 0 55 execution_time = 0.0029 x= -0.

0713 0.3155 0. 1.2217 -0.0012 0.2965 -0.0455 >> .0211 -0.2934 -0.