本人想利用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.