%problem P4.1
a=[10 -2 1;-2 10 -2;-2 -5 10];
b=[9;12;18];
%solve with gs1
[x1,c1]=gs1(a,b)
%solve with gs2
[x2,c2]=gs2(a,b)
%solve with jacobi1
[x3,c3]=jacob1(a,b)
%solve with jacob2
[x4,c4]=jacob2(a,b)
%compare results
disp('no of iterations')
[c1 c2 c3 c4]
disp(' solution and error')
[x1 x2 x3 x4 b-a*x1]
%calculate iteration matrix and max eigenvalue
l=tril(a,-1);d=diag(diag(a));u=triu(a,1);
%jacobi
cj=inv(d)*(l+u);specj=max(abs(eig(cj)))
%Gauss-Seidel
cgs=inv(d+l)*u;specgs=max(abs(eig(cgs)))
