You are on page 1of 1

%

%
%
%
%
%
%
%
%
%

Solve the System of linear equations using Gauss-seidel method:


1x1+1x2+1x3= 6
1x1+2x2-1x3= 2
2x1+1x2+2x3=10
Initial velues: x2=0, x3=0
Iterate until the value of error for x1 is less than 0.01%
Solution:
x1= 6-1x2-1x3
x2=( 2-1x1+1x3)/2
x3=(10-2x1-1x2)/2

clear;clc;format('long','g');
i=1
x2(i)=0;x3(i)=0
error_x1(i)=9999;
while error_x1(i) >= 0.01
x1(i+1)= 6-1*x2(i)-1*x3(i);
x2(i+1)=( 2-1*x1(i+1)+1*x3(i))/2;
x3(i+1)=(10-2*x1(i+1)-1*x2(i+1))/2;
error_x1(i+1)=abs((x1(i+1)-x1(i))/x1(i+1))*100;
error_x2(i+1)=abs((x2(i+1)-x2(i))/x2(i+1))*100;
error_x3(i+1)=abs((x3(i+1)-x3(i))/x3(i+1))*100;
i=i+1
end
disp('
x1
disp([x1',error_x1'])
disp('
x2
disp([x2',error_x2'])
disp('
x3
disp([x3',error_x3'])

error(%)');
error(%)');
error(%)');

You might also like