24小时热门版块排行榜    

查看: 1649  |  回复: 3
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

史迪仔and

新虫 (初入文坛)

[求助] 曲线拟合方法 已有1人参与

大家好,我最近在做一个非线性拟合的课题,参数只要一变多就拟合不出来,我知道确定的公式f=x.^2./(a(1)+sqrt(a(1).^2-(a(2)+1)*x.^2))+a(3)*x.^4+a(4)*x.^6+a(5)*x.^8+a(6)*x.^10+a(7)*x.^12+a(8)*x.^14+a(9)*x.^16+a(10)*x.^18+a(11)*x.^20);拟合出a,自己写的程序

[x,y]=textread('非球面数据.txt','%f %f');
plot(x,y,'o')
hold on
s = fitoptions('Method','NonlinearLeastSquares','Algorithm', 'levenberg-marquardt','Lower',[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1], 'Upper',[Inf,Inf,Inf,Inf,Inf,Inf,Inf,Inf,Inf,Inf,Inf]);
f = fittype('x.^2./(a(1)+sqrt(a(1).^2-(a(2)+1)*x.^2))+a(3)*x.^4+a(4)*x.^6+a(5)*x.^8+a(6)*x.^10+a(7)*x.^12+a(8)*x.^14+a(9)*x.^16+a(10)*x.^18+a(11)*x.^20','options',s);
[c,gof] = fit(x,y,f,'StartPoint',[4,0,0,0,0,0,0,0,0,0,0]);

真心希望能够得到你们的帮助,自己编写的LM算法,结果调试没问题,一运行就崩溃了,现在带用他自己的函数,又做不出来,不知道这样的方程用怎样的拟合方法效果最好呢?matlab里面有好多种拟合算法吗,自己看了看基本都是局部最优解,有没有全局最优呢?希望有经验的人能给以指导。1stopt如果拟合的话能生成exe文件吗,我最终想做成一个通用的程序,而不是只要一次结果。先谢谢各位了
回复此楼

» 本帖附件资源列表

  • 欢迎监督和反馈:小木虫仅提供交流平台,不对该内容负责。
    本内容由用户自主发布,如果其内容涉及到知识产权问题,其责任在于用户本人,如对版权有异议,请联系邮箱:xiaomuchong@tal.com
  • 附件 1 : 非球面数据.txt
  • 2014-12-12 17:29:24, 13.58 K

» 收录本帖的淘帖专辑推荐

动力学拟合

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

史迪仔and

新虫 (初入文坛)

引用回帖:
2楼: Originally posted by feixiaolin at 2014-12-12 20:36:34
考虑正交多项式,或切比雪夫拟合什么的,你的阶数太高了。

好,我看看,matlab中怎样使拟合的结果只取实数解呢,我拟合出来结果好多虚步啊
3楼2014-12-12 22:28:23
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 4 个回答

feixiaolin

荣誉版主 (文坛精英)

优秀版主

考虑正交多项式,或切比雪夫拟合什么的,你的阶数太高了。
2楼2014-12-12 20:36:34
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dbb627

荣誉版主 (著名写手)

【答案】应助回帖

感谢参与,应助指数 +1
全局算法
CODE:
function Insphere_fit
[xdata,ydata]=textread('非球面数据.txt','%f %f');
plot(xdata,ydata,'o')
hold on
myfun=@(x,xdata)xdata.^2./(x(1)+sqrt(x(1).^2-(x(2)+1)*xdata.^2))+x(3)*xdata.^4+x(4)*xdata.^6+x(5)*xdata.^8+x(6)*xdata.^10+x(7)*xdata.^12+x(8)*xdata.^14+x(9)*xdata.^16+x(10)*xdata.^18+x(11)*xdata.^20;
tic
x0=[4 rand(1,10)];
format shortg
ms=MultiStart;
F =@(x)norm(xdata.^2./(x(1)+sqrt(x(1).^2-(x(2)+1)*xdata.^2))+x(3)*xdata.^4+x(4)*xdata.^6+x(5)*xdata.^8+...
    x(6)*xdata.^10+x(7)*xdata.^12+x(8)*xdata.^14+x(9)*xdata.^16+x(10)*xdata.^18+x(11)*xdata.^20-ydata);
opts=optimset('Algorithm', 'interior-point');
problem=createOptimProblem('fmincon','x0',x0,...
    'objective',F,'lb',[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],...
    'ub',[Inf,Inf,Inf,Inf,Inf,Inf,Inf,Inf,Inf,Inf,Inf],'options',opts);
[xminm,fminm,flagm,outptm,manyminsm]=run(ms,problem,20)
t2=toc
figure;plot(xdata,ydata,'r-*',xdata,myfun(xminm,xdata),'bo-')
legend('real','model')
Text2=['利用全局算法 multistart和fmincon估计得到的参数,耗时',num2str(t2),'s'];
title(Text2)

MultiStart completed the runs from all start points.

All 20 local solver runs converged with a positive local solver exit flag.

xminm =

  Columns 1 through 5

       132.11       1497.3       12.388     -0.99669     -0.98238

  Columns 6 through 10

     -0.99812      0.68971     -0.16267     0.017723  -0.00074323

  Column 11

-4.2727e-006


fminm =

       788.62


flagm =

     1


outptm =

                funcCount: 15871
         localSolverTotal: 20
       localSolverSuccess: 20
    localSolverIncomplete: 0
    localSolverNoSolution: 0
                  message: [1x128 char]


manyminsm =

  1x20 GlobalOptimSolution

  Properties:
    X
    Fval
    Exitflag
    Output
    X0




t2 =

       59.298
曲线拟合方法
untitled.jpg

The more you learn, the more you know, the more you know, and the more you forget. The more you forget, the less you know. So why bother to learn.
4楼2014-12-14 23:52:47
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 欢迎发来filecode的Mz6后的代码验证其规律 +36 医学老男孩 2026-08-13 85/4250 2026-08-17 21:23 by lcmdlut
[基金申请] filecode=后面第一个是大写字母 +8 wangze12014 2026-08-14 10/500 2026-08-17 17:05 by xter9665
[基金申请] 时间戳变了,能看出什么问题? +4 基诺咪客 2026-08-17 4/200 2026-08-17 16:10 by Vivilian
[基金申请] 哪位老哥知道今年的国自然具体哪一天放榜? +12 Ldrop2023 2026-08-13 15/750 2026-08-17 15:02 by 小豌豆_发芽
[基金申请] 今天系统多次维护,明天很可能放榜! +8 zju2000 2026-08-16 9/450 2026-08-17 12:20 by lmz0216
[基金申请] 时间戳又变了8-15 +13 archvillain 2026-08-15 25/1250 2026-08-16 20:13 by zhaosm1982
[基金申请] 2027广东省杰青 +3 奶牛小黑 2026-08-15 6/300 2026-08-16 20:07 by 奶牛小黑
[基金申请] 快农历七夕节了,轻松一下,男人悄悄话,女施主请不要进来。 +3 Tide man 2026-08-14 3/150 2026-08-16 17:47 by jurkat.1640
[基金申请] 咱们一起用铁证分析2026国家社科基金中标与否 +7 启萌科技 2026-08-12 26/1300 2026-08-16 12:35 by 启萌科技
[基金申请] 有时候,自然基金真的不能太认真 (我的申报经验) +10 majunge000 2026-08-11 12/600 2026-08-16 08:18 by xli1984
[精细化工] 招聘 金属平磨液,抛光液研发工程师 +3 小天0311 2026-08-14 3/150 2026-08-16 07:31 by H9PLUS
[基金申请] 各位道友,我要去昆明玩几天,回来见。 +7 Tide man 2026-08-14 8/400 2026-08-15 01:11 by arzu_hma
[基金申请] 是这周出结果还是下周出结果? +4 yuleib84 2026-08-11 4/200 2026-08-14 23:05 by lfy8008
[硕博家园] 读博的好处 +4 lnee 2026-08-11 4/200 2026-08-14 10:20 by ahsoarli
[基金申请] 重要来源:本周末出结果 +10 瞬息宇宙 2026-08-12 10/500 2026-08-13 15:46 by likettle
[基金申请] Filecode 又变了,巨变 +3 WH3796 2026-08-12 4/200 2026-08-13 14:13 by 小木虫6752397
[基金申请] 分享一下我之前已中青C的计划书的filecode +4 布布和一二 2026-08-11 5/250 2026-08-13 12:56 by cratir
[基金申请] 结合人工智能,周易传统文化,filecode打分制来了,3分以上希望很大。 +3 Tide man 2026-08-12 4/200 2026-08-13 08:35 by ZJTJZ
[基金申请] 2019年青年基金涵评意见,大家看看几个A,几个B? +11 Tide man 2026-08-11 11/550 2026-08-13 07:35 by 撸猫猫
[基金申请] 什么时候出结果,有咨询渠道??? +3 Tide man 2026-08-11 3/150 2026-08-11 17:54 by kudofaye
信息提示
请填处理意见