Objective function is returning Inf or NaN values at initial point. lsqcurvefit cannot continue.
7 次查看(过去 30 天)
显示 更早的评论
Hi guys, I tried to fitting my data with following code
k0= 3.5e+05; % (s-1)
lamda=7.5e-10; % (m)
n=0.92e-20;
KbT=4.11e-21; % (J)
p=[k0, lamda, n];
func=@(p,ydata)2*p(1)*p(2)*sinh((0.072*cosd(70)-0.0623.*cosd(ydata))/(2*KbT*p(3)));
lb=[1e+1; 1e-12; 1e-15]; % lower bound
ub=[1e+9; 1e-6; 1e-25]; % upper bound
f=lsqcurvefit(func, p, ydata, xdata, lb,ub);
plot(xdata,ydata,'ko',xdata,func(f,ydata),'b-')
But, when I ran, the code results in:
Error using lsqncommon
Objective function is returning Inf or NaN values at initial point. lsqcurvefit cannot continue.
Error in lsqcurvefit (line 274)
lsqncommon(funfcn,xCurrent,lb,ub,options,defaultopt,optimgetFlag,caller,...
Error in mkt (line 21)
f=lsqcurvefit(func, p, ydata, xdata, lb,ub);
I tried to look at my data, but it looks find to me. Please see the attachment for the data reference, column 1 is xdata, column 2 is ydata.
Thanks for suggestion.
0 个评论
采纳的回答
Torsten
2023-10-12
编辑:Torsten
2023-10-12
Before you call lsqcurvefit, you should call your function "func" with the initial guess values for the parameters to see what it returns. So insert the command
test = func(p,ydata)
before the line
f=lsqcurvefit(func, p, ydata, xdata, lb,ub);
Further it is usual that you have a function ydata = func(p,xdata). You reversed the roles of xdata and ydata: xdata = func(p,ydata). You should check whether this is really what you want.
Further your model depends on only one parameter, not three. The expression
2*p(1)*p(2)/(2*KbT*p(3))
can be seen as one parameter P you try to estimate. It's not possible to distinguish between p(1), p(2) and p(3) because they are subsummed in one expression.
To understand this, imagine you try to fit a model
ydata = p(1)*p(2)*xdata
If the optimizer returns p(1) = 2, p(2) = 5, would this in any way be better than p(1) = 1, p(2) = 10 or p(1) = 2.5, p(2) = 4 ?
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!