3、f,%f",x1,x2,x3,x4);scanf("%lf",&a[i][j]);(这一步只是为了看到运行的结果)}运行结果列主元消元法function[x,det,flag]=Gauss(A,b)[n,m]=size(A);nb=length(b);flag='OK';det=1;x=zeros(n,1);fork=1:n-1max1=0;fori=k:nifabs(A(i,k))>max1max1=abs(A(i,k));r=i;endendifmax1<1e-10flag='failure';return;endifr>kf
4、orj=k:nz=A(k,j);A(k,j)=A(r,j);A(r,j)=z;endz=b(k);b(k)=b(r);b(r)=z;det=-det;endfori=k+1:nm=A(i,k)/A(k,k);forj=k+1:nA(i,j)=A(i,j)-m*A(k,j);endb(i)=b(i)-m*b(k);enddet=det*A(k,k);enddet=det*A(n,n)ifabs(A(n,n))<1e-10flag='failure';return;endx(n)=b(n)/A(n,n);fork=n-1:-1:1fo
5、rj=k+1:nb(k)=b(k)-A(k,j)*x(j);endx(k)=b(k)/A(k,k);end运行结果:雅可比迭代法functiony=jacobi(a,b,x0)D=diag(diag(a));U=-triu(a,1);L=-tril(a,-1);B=D(L+U);f=Db;y=B*x0+f;n=1;whilenorm(y-x0)>1e-4x0=y;y=B*x0+f;n=n+1;endyn高斯赛德尔迭代法functiony=seidel(a,b,x0)D=diag(diag(a));U=-triu(a,1);L=
6、-tril(a,-1);G=(D-L)U;f=(D-L)b;y=G*x0+f;n=1;whilenorm(y-x0)>10^(-4)x0=y;y=G*x0+f;n=n+1;endynSOR迭代法functiony=sor(a,b,w,x0)D=diag(diag(a));U=-triu(a,1);L=-tril(a,-1);lw=(D-w*L)((1-w)*D+w*U);f=(D-w*L)b*w;y=lw*x0+f;n=1;whilenorm(y-x0)>10^(-4)x0=y;y=lw*x0+f;n=n+1;endyn1
7、.分段线性插值:functiony=fdxx(x0,y0,x)p=length(y0);n=length(x0);m=length(x);fori=1:mz=x(i);forj=1:n-1ifz8、+1),y0(j+1));endend结果0.394040.380070.356932.分段二次插值:functiony=fdec(x0,y0,x)p=length(y0);n=length(x0);m=length(x);fori=1:mz=x(