Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 工程数学软件 > MATLAB论坛
MATLAB论坛 一切MATLAB相关问题在此讨论。
查看投票结果: 你感觉这贴怎么样
很好 2 100.00%
不错 0 0%
一般 0 0%
不好 0 0%
投票者: 2. 您不可以参加此投票

回复
 
主题工具 显示模式
旧 2008-11-19, 22:59   #1
nanhaizi9898
初级会员
 
注册日期: 2008-11-02
年龄: 37
帖子: 2
声望力: 0
nanhaizi9898 正向着好的方向发展
默认 [原创]新作的程序

现在学习MATLAB要多看人家的程序,在程序中学习各种函数的使用。在论坛很少看到牛人分享程序给我们学习,本人现在也在学习MATLAB,今天做了个关于插值和拟合问题的




程序如下:clf,a=-1;b=1;n=100;
g=inline('x^2-x^4');xx=linspace(a,b,n);
for i=1:n
gx(i)=g(xx(i));
end
ymin=min(gx)*0.8;
ymax=max(gx)*1.2;
subplot(2,2,1),
plot(xx,gx,'--'),grid,hold on,axis([a b ymin ymax]);title('近邻插值')
subplot(2,2,2),
plot(xx,gx,'--'),grid,hold on,axis([a b ymin ymax]);title('线性插值')
subplot(2,2,3),
plot(xx,gx,'--'),grid,hold on,axis([a b ymin ymax]);title('样条插值')
subplot(2,2,4),
plot(xx,gx,'--'),grid,hold on,axis([a b ymin ymax]);title('多项式拟合')
button=1
x1=[a];y1=[gx(1)]; %or y1=[gx(1)]
while button==1
[xi,yi,button]=ginput(1);
subplot(2,2,1),h=plot(xi,yi,'ro');
subplot(2,2,2),h=plot(xi,yi,'ro');
subplot(2,2,3),h=plot(xi,yi,'ro');
subplot(2,2,4),h=plot(xi,yi,'ro');
x1=[xi x1];y1=[yi y1];
end
x1=[b x1];y1=[gx(n),y1];
xx=linspace(a,b,n);
ynearest=interp1(x1,y1,xx,'nearest');
ylinear=interp1(x1,y1,xx,'linear');
yspline=interp1(x1,y1,xx,'spline');
[p,c]=polyfit(x1,y1,4);
ypolyfit=polyval(p,xx);
subplot(2,2,1),h=plot(xx,ynearest,'r-');set(h,'linewidth',2);
subplot(2,2,2),h=plot(xx,ylinear,'r-');set(h,'linewidth',2);
subplot(2,2,3),h=plot(xx,yspline,'r-');set(h,'linewidth',2);
subplot(2,2,4),h=plot(xx,ypolyfit,'r-');set(h,'linewidth',2);
nanhaizi9898 当前离线   回复时引用此帖
旧 2008-12-18, 20:18   #2
sunspots
初级会员
 
注册日期: 2008-12-18
年龄: 26
帖子: 1
声望力: 0
sunspots 正向着好的方向发展
默认 回复: [原创]新作的程序

谢谢你,楼主辛苦了
sunspots 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码


相似的主题
主题 主题作者 版面 回复 最后发表
[资料]BP网络总结及应用实例 guofeng0108 MATLAB论坛 37 2012-06-11 22:08
[求助]如何求多幅图像的平均图像 snowtv7 MATLAB论坛 2 2009-02-26 16:24
[求助]判断一元多项式函数的编程问题 剑八 MATLAB论坛 0 2008-12-10 19:48
积分输出结果格式问题 bangbg MATLAB论坛 1 2008-06-18 23:45
Simplify Instrument Communication: Using Instrument Drivers with the Instrument Contr TechnicalArticles MATLAB技术文章 0 2008-01-06 16:32


所有时间均为北京时间。现在的时间是 03:25


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.