nctionx=Jocabi(n)A=hilb(n);x_a=ones(n,1);b=A*x_a;eps=1e-4;n=length(b);N=50;x=zeros(n,1);y=zeros(n,1);fork=1:Nsum=0;fori=1:ny(i)=(b(i)-A(i,1:n)*x(1:n)+A(i,i)*x(i))/A(i,i);endfori=1:nsum=sum+(y(i)-x(i))^2;endifsqrt(sum)<epsbreak;elsefori=1:nx(i)=y(i);endendend②SOR方法(文件SOR_3.m)functionSOR_3(n,w)%x_aΪ¾«È·½âif(w<=0||w>=2)error('²ÎÊý·¶Î§´íÎó');return;endx0=zeros(n,1);A=hilb(n);x_a=ones(n,1);b=A*x_a;eps=1e-4;D=diag(diag(A));%ÇóAµÄ¶Ô½Ç¾ØÕóL=-tril(A,-1);%ÇóAµÄÏÂÈý½ÇÕóU=-triu(A,1);%ÇóAµÄÉÏÈý½ÇÕóB=inv(D-L*w)*((1-w)*D+w*U);f=w*inv((D-L*w))*b;x=B*x0+f;n=1;%µü´ú´ÎÊýwhilenorm(x-x0)>=epsx0=x;x=B*x0+f;n=n+1;if(n>=2000)disp('Warning:µü´ú´ÎÊýÌ«¶à£¬¿ÉÄܲ»ÊÕÁ²£¡');return;endenddisp('Hx=bµÄ½âΪ£º');xdisp('µü´ú´ÎÊýΪ£º');n③控制台输入代码:>>x=Jocabi(6)>>x=Jocabi(8)>>x=Jocabi(10)>>SOR_3(6,1)>>SOR_3(6,1.25)>>SOR_3(6,1.5)