[转载]matlab差值计算

标签:
转载 |
分类: Matlab |
原文地址:matlab差值计算作者:彼岸花
http://s8/bmiddle/70458e55gad0a9fd11007&690
matlab提供了内置的差值函数,包括线性插值(liner),三次插值(cubic),三次样条插值(spline)
命令的格式 yi = interp1(t,y,ti,'method')
t = 0:10; y = sin(t); ti =
0:0.25:10;
y1 =
interp1(t,y,ti,'linear');
y2=
interp1(t,y,ti,'cubic');
y3 =
interp1(t,y,ti,'spline');
subplot(2,2,1),plot(t,y,'o');
subplot(2,2,2),plot(ti,y1);
subplot(2,2,3),plot(ti,y2);
subplot(2,2,4),plot(ti,y3,'r');
所得结果即为上图所示。
例2:
已知观测数据:
(0,-0.447),(0.1,1.978),(0.2,3.28),(0.3,6.16),(0.4,7.08),(0.5,7.34),(0.6,7.66),(0.7,9.56),(0.8,9.48),(0.9,9.3),(1.11.2)
绘制插值曲线
http://s16/bmiddle/70458e55gad0aec379a6f&690
圆圈表示插值点,红色为spline插值的结果,蓝色为cubic插值的结果
圆圈表示插值点,红色为spline插值的结果,蓝色为cubic插值的结果
代码:
t = 0:0.1:1;
y = [-0.447,1.978,3.28,6.16,7.08,7.34,7.66,9.56,9.48,9.3,11.2]
plot(t,y,'o')
hold on;
grid on;
ti = 0:0.01:1;
y1 = interp1(t,y,ti,'spline');
y2 = interp1(t,y,ti,'cubic');
plot(ti,y1,'r');
plot(ti,y2);
y = [-0.447,1.978,3.28,6.16,7.08,7.34,7.66,9.56,9.48,9.3,11.2]
plot(t,y,'o')
hold on;
grid on;
ti = 0:0.01:1;
y1 = interp1(t,y,ti,'spline');
y2 = interp1(t,y,ti,'cubic');
plot(ti,y1,'r');
plot(ti,y2);
所得结果如上图所示