n<4 it_max=100;endРif nargin<3 ep=1e-5;endРk=0; x=zeros(n,1);y=zeros(n,1);index=1;Рwhile 1Р for i=1:nР y(i)=b(i);Р for j=1:nР if j~=iР y(i)=y(i)-A(i,j)*x(j);Р endР endР if abs(A(i,i))<1e-10|k==it_maxР index=0;return;Р endР y(i)=y(i)/A(i,i);Р endР k=k+1;Р if norm(y-x,inf)<epР break;Р endР x=y;РendР Gauss_Seidel.m如下:Рfunction [x,k,index]=Gauss_Seidel(A,b,ep,it_max)Р[n,m]=size(A); nb=length(b);Рif n~=mР error('The rows and columns of matrix A must be equal'); return;РendРif m~=nbР error('The columns of A must be equal the length of b'); return;РendРif nargin<4 it_max=100; endРif nargin<3 ep=1e-5; endРk=0; x=zeros(n,1);y=zeros(n,1);index=1;Рwhile 1Р y=x;Р for i=1:nР z=b(i);Р for j=1:nР if j~=iР z=z-A(i,j)*x(j);Р endР endР if abs(A(i,j))<1e-10|k==it_maxР index=0;return;Р endР z=z/A(i,i);x(i)=z;