通过matlab建模,用分段线性和三次样条两种插值方法计算x坐标轴每改变0.1时得出y坐标的变化。
x | 0 | 3 | 5 | 7 | 9 | 11 | 12 | 13 | 14 | 15 |
y | 0 | 1.2 | 1.7 | 2.0 | 2.1 | 2.0 | 1.8 | 1.2 | 1.0 | 1.6 |
通过对上述数据的分析得出步长很小的(x,y)坐标
其中主要步骤如下:
(1)分别写出线性插值与三次样条插值的代码
(2)绘画其图形
(3)分析并总结
(4)得出结论并检验。
运行结果如下:
代码如下:
附录
x0=[0 3 5 7 9 11 12 13 14 15];
y0=[0 1.2 1.7 2.0 2.1 2.0 1.8 1.2 1.0 1.6];
x=0:0.1:15;
y1=interp1(x0,y0,x);
y2=interp1(x0,y0,x,'spline');
pp1=csape(x0,y0);
y3=ppval(pp1,x);
pp2=csape(x0,y0,'second');
y4=ppval(pp2,x);
[x',y1',y2',y3',y4']
subplot(1,3,1)
plot(x0,y0,'+',x,y1)
title('Piecewise linear')
subplot(1,3,2)
plot(x0,y0,'+',x,y2)
title('Spline1')
subplot(1,3,3)
plot(x0,y0,'+',x,y3)
title('Spline2')
dx=diff(x);
dy=diff(y3);
dy_dx=dy./dx;
dy_dx0=dy_dx(1)
ytemp=y3(131:151);
ymin=min(ytemp);
index=find(y3==ymin);
xmin=x(index);
[xmin,ymin]