1、设有方程组 12531x042321xx用雅可比迭代法和塞德尔迭代法分别求解此方成组,当 时终止,并4)()1(0| kkx写出相应的迭代法的迭代矩阵1,雅可比迭代法m 文件:function x=jacobi(A,b,P,delta,n)N=length(b);for k=1:nfor j=1:Nx(j)=(b(j)-A(j,1:j-1,j+1:N)*P(1:j-1,j+1:N)/A(j,j);enderr=abs(norm(x-P);P=x;if(err clear all;A=5,2,1;-1,4,2;2,-3,10;b=-12,20,3;P=0,0,0;x=jacobi(A,b,P,1
2、e-4,20)结果:P =-4.00003.00002.0000k =18err =5.3233e-005B = %迭代矩阵0 -0.5000 -0.10000.2000 0 -0.2000-0.4000 0.7500 0x =-4.00003.00002.00002,高斯-塞德尔迭代法m 文件:function x=Seidel(A,b,P,delta,n)N=length(b);for k=1:nfor j=1:Nif j=1x(1)=(b(1)-A(1,2:N)*P(2:N)/A(1,1);elseif j=Nx(N)=(b(N)-A(N,1:N-1)*(x(1:N-1)/A(N,N);
3、elsex(j)=(b(j)-A(j,1:j-1)*x(1:j-1)-A(j,j+1:N)*P(j+1:N)/A(j,j);endenderr=abs(norm(x-P);P=x;if(err clear all;A=5,2,1;-1,4,2;2,-3,10;b=-12,20,3;P=0,0,0;x=Seidel(A,b,P,1e-4,20)结果:P =-4.00003.00002.0000k =9err =4.3642e-005B = %迭代矩阵-0.5000 -0.2000 -0.1000-0.0625 -0.5250 -0.26250.0406 -0.0588 -0.5294x =-4.00003.00002.0000