主要是体现出高次插值的病态性质,即龙格问题
Matlab主程序
x1 = linspace(-1.0,10,10);
y1=1./(1+25*x1.*x1);
x2 = linspace(-1.0,10,20);
y2=1./(1+25*x2.*x2);
x = linspace(-1,1,50);
M = 1;
[poly1,R,A] = Newton(x1, y1, x, M);
[poly2,R,A] = Newton(x2, y2, x, M);
s1=interp1(x1,y1,x,'spline');
s2=interp1(x2,y2,x,'spline');
y=1./(1+25*x.*x);
plot(x, y, '-k', x, poly1, '-r', x, poly2, '-b',x,s1,'-g',x,s2,'-m');
legend('函数','多项式n1','多项式n2','三次样条插值n1','三次样条插值n2');
结果图展示
问题总结
- 用第一题的语句基本都能实现
- 矩阵乘除法的时候要注意点乘和点除,对矩阵的运算需要复习