24小时热门版块排行榜    

查看: 1626  |  回复: 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的回帖

feixiaolin

荣誉版主 (文坛精英)

优秀版主

考虑正交多项式,或切比雪夫拟合什么的,你的阶数太高了。
2楼2014-12-12 20:36:34
已阅   回复此楼   关注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的回帖

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的回帖
相关版块跳转 我要订阅楼主 史迪仔and 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 2019年青年基金涵评意见,大家看看几个A,几个B? +5 Tide man 2026-08-11 5/250 2026-08-12 09:24 by kangban
[基金申请] 奇怪,两个人的filecode固定段从头到尾一模一样 +7 布布和一二 2026-08-10 10/500 2026-08-12 09:12 by 布布和一二
[基金申请] 有时候,自然基金真的不能太认真 (我的申报经验) +3 majunge000 2026-08-11 4/200 2026-08-11 20:13 by lch2012
[基金申请] 帮忙看看fileCode +7 wwncly 2026-08-10 13/650 2026-08-11 19:36 by 冰心玉壶晴
[硕博家园] 读博的好处 +3 lnee 2026-08-11 3/150 2026-08-11 18:10 by 希望我好好的
[基金申请] 分享一下我之前已中青C的计划书的filecode +3 布布和一二 2026-08-11 4/200 2026-08-11 15:20 by aasahr
[基金申请] 我的国基提前知道中了,可是同事的操作让我实在接受不了,怎么会有这样的人 +8 家与远方 2026-08-10 13/650 2026-08-11 09:49 by 家与远方
[基金申请] 确定了,国自然21号放榜 +6 布布和一二 2026-08-10 7/350 2026-08-10 19:15 by 2000zf36392
[基金申请] 关于代码变化问题,想知道的进来 +17 且听虎啸 2026-08-07 24/1200 2026-08-10 18:35 by zhangduo2008
[基金申请] 关于Filecode分析方法 +3 majunge000 2026-08-10 3/150 2026-08-10 15:46 by lch2012
[基金申请] 国自然结果 +4 Vierhys 2026-08-10 8/400 2026-08-10 15:06 by Vierhys
[基金申请] 据悉今年马上要出结果了 +7 瞬息宇宙 2026-08-10 8/400 2026-08-10 12:42 by Vivilian
[基金申请] 这样的filecode谁见过 +11 布布和一二 2026-08-08 22/1100 2026-08-10 11:10 by wmfsnow
[基金申请] 关于filecode,很负责任的告诉大家 +6 爱看书的可乐 2026-08-08 7/350 2026-08-08 22:13 by a_niu
[基金申请] 关于豆爷回答的JTJC与%2F数量 +5 yang182083 2026-08-06 7/350 2026-08-08 18:29 by zhanghaozhu
[基金申请] 国基金的申报应该改成非等额制,评价高的钱多评价低的钱少,但是增加资助率 +7 a089 2026-08-07 7/350 2026-08-08 18:05 by gltch
[基金申请] 关于filecode +4 布布和一二 2026-08-07 7/350 2026-08-07 22:55 by zhanghaozhu
[基金申请] 固定端突然变了,今天 +6 archvillain 2026-08-06 10/500 2026-08-07 16:03 by 医学老男孩
[基金申请] filecode变化情况 +6 布布和一二 2026-08-07 22/1100 2026-08-07 14:45 by 且听虎啸
[基金申请] filecode +8 布布和一二 2026-08-06 11/550 2026-08-06 20:41 by tangpu318
信息提示
请填处理意见