1 / 28
文档名称:

数值分析实验二(matlab)插值法.doc

格式:doc   大小:136KB   页数:28页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

数值分析实验二(matlab)插值法.doc

上传人:zxwziyou8 2022/3/7 文件大小:136 KB

下载得到文件列表

数值分析实验二(matlab)插值法.doc

文档介绍

文档介绍:实验二 插值法
(多项式插值的振荡现象)3
实验要求1:3
程序:3
主函数:3
实验结果:5
实验要求2:6
);
s=;
for k=1:n
p=;
for j=1:n
if j~=k
p=p*(z-x0(j))/(x0(k)-x0(j));
end
end
s=p*y0(k)+s;
end
y(i)=s;
end
主函数:
x1=[-5::5];y1=x1./(1+x1.^4);
x2=[-5:2:5];y2=x2./(1+x2.^4);
x3=[-5:1:5];y3=x3./(1+x3.^4);
x4=[-5::5];y4=x4./(1+x4.^4);
x5=[-5::5];y5=x5./(1+x5.^4);
x6=[-5::5];y6=x6./(1+x6.^4);
x0=[-5::5];
subplot(4,2,1)
y7=x0./(1+x0.^4);
plot(x0,y7,'-b')
y0=lagrange(x1,y1,x0);
y1=x0./(1+x0.^4);
subplot(4,2,2)
plot(x0,y0,'--b')
y0=lagrange(x2,y2,x0);
y2=x0./(1+x0.^4);
subplot(4,2,3)
plot(x0,y0,'-g')
y0=lagrange(x3,y3,x0);
y3=x0./(1+x0.^4);
subplot(4,2,4)
plot(x0,y0,'--g')
y0=lagrange(x4,y4,x0);
y4=x0./(1+x0.^4);
subplot(4,2,5)
plot(x0,y0,'-r')
y0=lagrange(x5,y5,x0);
y5=x0./(1+x0.^4);
subplot(4,2,6)
plot(x0,y0,'--r')
y0=lagrange(x6,y6,x0);
y6=x0./(1+x0.^4);
subplot(4,2,7)
plot(x0,y0,'-y')
数值实验结果及分析:
实验结果:
图一为原函数曲线。然后图二至图七为插值点分别为4个、5个、10个、20个、25个、100个时的函数图像。
实验分析
与第一问得到的拟合函数的结果相类似,随着插值节点愈多,在中间阶段得到的函数图像叫原函数比较相似,但是在两端出现了明显的震荡,并且随着插值点的增多,震荡越来越大且不可控制。
(2)对g(x)=arctan x
程序:
M文件名:

Lagrange函数:
%lagrange insert
function y=lagrange(x0,y0,x)
n=length(x0);m=length(x);
for i=1:m
z=x(i);
s=;
for k=1:n
p=;
for j=1:n
if j~=k
p=p*(z-x0(j))/(x0(k)-x0(j));
end
end
s=p*y0(k)+s;
end
y(i)=s;
end
主函数:
x1=[-5::5];y1=atan(x1);
x2=[-5:2:5];y2=atan(x2);
x3=[-5:1:5];y3=atan(x3);
x4=[-5::5];y4=atan(x4);
x5=[-5::5];y5=atan(x5);
x6=[-5::5];y6=atan(x6);
x0=[-5::5];
subplot(4,2,1)
y7=atan(x0);
plot(x0,y7,'-b')
y0=lagrange(x1,y1,x0);
y1=atan(x1);
subplot(4,2,2)
plot(x0,y0,'--b')
y0=lagrange(x2,y2,x0);
y2=atan(x2);
subplot(4,2,3)
plot(x0,y0,'-g')