当前位置:文档之家› 龙格现象实验报告1

龙格现象实验报告1

t2=interp1(hours,temps,h,'nearest');
t3=interp1(hours,temps,h,'linear');
t4=interp1(hours,temps,h,'cubic');
subplot(2,2,1); plot(hours,temps,' bo',h,t1,'r'); title('spline ');%×÷ͼ
那么如何提高插值精度呢?采用分段插值是一种办法。




多种插值对比
functiony=fun(x);
y=5./(1+x.^2);
end
hours=-5:5;
h=-5:0.1:5;
temps=fun(hours);
t1=interp1(hours,temps,h,'spline');%(Ö±½ÓÊä³öÊý¾Ý½«ÊǺܶàµÄ)
subplot(2,2,2); plot(hours,temps,'bo',h,t2,'r'); title(' nearest');
subplot(2,2,3); plot(hours,temps,'bo',h,t3,'r'); title('linear');
subplot(2,2,4); plot(hours,temps,'bo',h,t4,'r', h,t1,'g'); title('cubic-spline');
1、a=1时,1)取n=4,作出f(x)和插值多项式的曲线图;
2)取n=10,作出f(x)和插值多项式的曲线图;
2、a=0.25时,1)取n=4,作出f(x)和插值多项式的曲线图;
2)取n=10,作出f(x)和插值多项式的曲线图;
3、分析上述曲线图,你可以得出什么结论?




拉格朗日插值的调用函数
x0=[-5:1:5];
y0=5./(1+x0.^2);
x=[-5:0.1:5];
y=lagrange(x0,y0,x);
y1=5./(1+x.^2);
plot(x,y,'--r')
holdon
plot(x,y1,'-b')
holdoff
2、a=0.25时,
1)取n=4
x0=[-5:2:5];
y0=5./(0.25*0.25+x0.^2);
数值分析实验报告
实验名称:观察龙格(Runge)现象实验
班级:12级信息与计算科学(1)班
姓名:
学号:33 16 17 59
实验日期:2014.10.11周次:6实验地点格朗日插值的龙格(Runge)现象.




对于函数 进行拉格朗日插值,取不同的节点数n,在区间[-5,5]上取等距间隔的节点为插值点,把f(x)和插值多项式的曲线画在同一张图上进行比较。(a可以取任意值)具体步骤:
x=[-5:0.1:5];
y=lagrange(x0,y0,x);
y1=5./(1+x.^2);
plot(x,y,'--r')
holdon
plot(x,y1,'-b')
holdoff
2)取
3)
4)a=0.25n=10
x0=[-5:1:5];
y0=5./(0.25*0.25+x0.^2);
x=[-5:0.1:5];
y=lagrange(x0,y0,x);
y1=5./(1+x.^2);
plot(x,y,'--r')
holdon
plot(x,y1,'-b')
holdoff






a=1时,
1)取n=4
a=1时,
2)取n=10
a=0.25时,
1)取n=4
a=0.25时,
2)取n=10
上述现象告诉我们,并不是插值多项式的次数越高(即插值节点越多)精度越高,从数值计算上可解释为高次插值多项式的计算会带来舍入误差的增大,从而引起计算失真。因此,实际应用做插值时一般只用一次、二次最多用三次插值多项式。
functiony=lagrange(x0,y0,x)
n=length(x0);m=length(x);
fori=1:m
z=x(i);
L=0.0;
forj=1:n
T=1.0;
fork=1:n
ifk~=j
T=T*(z-x0(k))/(x0(j)-x0(k));
end
end
L=T*y0(j)+L;
end
y(i)=L;
end
a=1时,
1)取
a=1;
n=4
x0=[-5:2:5];
y0=5./(1+x0.^2);
x=[-5:0.1:5];
y=lagrange(x0,y0,x);
y1=5./(1+x.^2);
plot(x,y,'--r')
holdon
plot(x,y1,'-b')
holdoff
2)取n=10
相关主题