加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

[转载]matlab差值计算

(2012-06-18 22:41:32)
标签:

转载

分类: Matlab
原文地址:matlab差值计算作者:彼岸花

http://s8/bmiddle/70458e55gad0a9fd11007&690

matlab提供了内置的差值函数,包括线性插值(liner),三次插值(cubic),三次样条插值(spline)

命令的格式 yi = interp1(t,y,ti,'method')

  其中:(t,y)为原始观测数据,是向量,必须定义

  ti为插值的t数据

  method为插值方法,liner:线性插值;cubic:三次插值;spline:三次样条插值

  例1:

 

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插值的结果
代码:
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);
所得结果如上图所示
 

 

0

  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有