A=[9 4 1;
1 6 0;
1 -2 -6];
C=[-17;
4;
14];
x=GaussSeidel(A,C)
function x=GaussSeidel(A,C)
x=zeros(size(C));
[n,n]=size(A);
residual=A*x-C
while max(abs(residual)) > 1.0e-8
for i=1:n
sum=0.0;
for j=1:n
if j~=i
sum=sum-A(i,j)*x(j);
end
end
x(i)=(sum+C(i))/A(i,i);
end
residual=A*x-C;
end
end