필터 지우기
필터 지우기

Objective function is returning Inf or NaN values at initial point. lsqcurvefit cannot continue.

조회 수: 6 (최근 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.

채택된 답변

Torsten
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개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by