全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 MATLAB等数学软件专版
6077 14
2015-04-25
       本人想利用matlab中的fit函数和fittype自定义的属性拟合Nelson-Siegel参数,但是写完程序老是报错,程序和错误如下:
程序如下:
yield = xlsread('20141118.xls','sheet4','I3:I21');
t = xlsread('20141118.xls','sheet4','C3:C21');
plot(t,yield,'o')
hold on
fo = fitoptions('Method','NonlinearLeastSquares',...
               'Lower',[0,0],...
               'Upper',[Inf,max(t)],...
               'StartPoint',[0.26 0.0041]);
ftp = fittype ('b0+b1*[(1-exp(-t/tau))/(t/tau)]+b2*[(1-exp(-t/tau))/(t/tau)-exp(-t/tau)]',...
               'dependent','yield','independent','t','coefficients',{'b0','b1','b2'},'problem','tau','options',fo);
[c2,gof2]= fit(t,yield,ftp,'problem',2)
plot(c2,'m')
hold off

错误提示:

Warning: Length of lower bounds is > length(x); ignoring extra bounds.
> In checkbounds at 29
  In lsqnsetup at 63
  In lsqcurvefit at 190
  In E:\studying software\Matlab\matlab r2012\toolbox\shared\optimlib\lscftsh.p>lscftsh at 37
  In cflscftsh at 8
  In curvefit\private\cflsqcurvefit at 55
  In fit>iFit at 373
  In fit at 109
  In firstNS at 11
Warning: Length of upper bounds is > length(x); ignoring extra bounds.
> In checkbounds at 38
  In lsqnsetup at 63
  In lsqcurvefit at 190
  In E:\studying software\Matlab\matlab r2012\toolbox\shared\optimlib\lscftsh.p>lscftsh at 37
  In cflscftsh at 8
  In curvefit\private\cflsqcurvefit at 55
  In fit>iFit at 373
  In fit at 109
  In firstNS at 11
Error using fit>iFit (line 415)
Not enough inputs to FITTYPE function.

Error in fit (line 109)
[fitobj, goodness, output, convmsg] = iFit( xdatain, ydatain, fittypeobj, ...

Error in firstNS (line 11)
[c2,gof2]= fit(t,yield,ftp,'problem',2);
Caused by:
    Failure in initial user-supplied objective function evaluation. LSQCURVEFIT cannot continue.




二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-4-25 21:13:47
fo = fitoptions('Method','NonlinearLeastSquares',...
                'Lower',[0,0],...
                'Upper',[Inf,max(t)],...
                'StartPoint',[0.26 0.0041 0.1]);
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-4-25 21:31:04
enxizheng 发表于 2015-4-25 21:13
fo = fitoptions('Method','NonlinearLeastSquares',...
                'Lower',[0,0],...
            ...
你有3个系数b0,b1,b2, 却只给了2个初值(StartPoint), 这可能是出错的原因
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-4-26 14:17:56
enxizheng 发表于 2015-4-25 21:31
你有3个系数b0,b1,b2, 却只给了2个初值(StartPoint), 这可能是出错的原因
恩恩,谢谢你的帮助,第一次用fittype,不太熟悉,调整后我拟合了一下,成功了,,我把初值赋好就行了,这里拟合好之后怎么查看对应的参数值呢? 我拟合的曲线
附件列表
fitnelsonsiegel.jpg

原图尺寸 16.31 KB

fitnelsonsiegel.jpg

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-4-26 15:10:26
heulingxiao 发表于 2015-4-26 14:17
恩恩,谢谢你的帮助,第一次用fittype,不太熟悉,调整后我拟合了一下,成功了,,我把初值赋好就行了,这 ...
参数结果存在你的 c2 变量中, 在命令窗口输入 c2, 回车即可.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-4-26 15:58:28
enxizheng 发表于 2015-4-26 15:10
参数结果存在你的 c2 变量中, 在命令窗口输入 c2, 回车即可.
做出来了,非常感谢!!!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群