MATLAB第三次实验报告.doc
MATLAB第三次实验报告1. 对高阶多项式编程求下面方程的解并绘图演示方程的解与扰动量的关系。程序:clcclearX=zeros(20,50);V=zeros(1,21);Z=linspace(0,0.00001,50);k=1;while k<=50 V(2)=Z(k); X(1:20,k)=roots(poly(1:20)+V); k=k+1;endm=1;while m<=20 figure(m),plot(Z,X(m,:); m=m+1;end2. 对,生成对应的Hilbert矩阵,计算矩阵的条件数;通过先确定解获得常向量b的方法,确定方程组最后,用矩阵分解方法求解方程组,并分析计算结果。程序:clcclearn=2;A=zeros(20,20); while n<=20 x=1:n; H=hilb(n); b=H*x' L U=lu(H); y=Lb;X=Uy; A(n,1:n)=x-X' n=n+1; end A3. 对函数 的Chebyshev点,编程进行Lagrange插值,并分析插值结果。程序:1for a=1:10 b=a+1; for c=1:b X(c)=cos(2*c-1)*pi/2/(a+1); Y(c)=1/(1+25*X(c)2); x=-1:0.05:1; end m=length(x); for i=1:m z=x(i);s=0; for k=1:b L=1; for j=1:b if j=k L=L*(z-X(j)/(X(k)-X(j); end end s=s+L*Y(k); end y(i)=s; end figure(1) plot(x,y,'r'); hold on; figure(2) plot(X,Y,'b+') hold onend2for a=2:2:10 b=a+1; X=linspace(-1,1,b); Y=1./(1+25*X.2); x=-1:0.05:1; m=length(x); for i=1:m z=x(i);s=0; for k=1:b L=1; for j=1:b if j=k L=L*(z-X(j)/(X(k)-X(j); end end s=s+L*Y(k); end y(i)=s; end figure(1) plot(x,y,'r'); hold on; figure(2) plot(X,Y,'b+') hold onend