lsqcurvefit : undefined values at initial point
이전 댓글 표시
a.mat contains the output of a ccd camera.
y = transpose(mean(a));
x = transpose(1:1280);
x0 = [600 1e4 .01];
parfit = lsqcurvefit(@fraunhof,x0,x,y)
function F = fraunhof(x,xdata)
beta = x(3).*(xdata-x(1));
sinbeta = sin(beta);
F = x(2).*sinbeta.^2./beta.^2;
Running this code returns the following error:
Error using snls (line 47)
Objective function is returning undefined values at initial point. lsqcurvefit cannot continue.
Error in lsqncommon (line 150)
[xC,FVAL,LAMBDA,JACOB,EXITFLAG,OUTPUT,msgData]=...
Error in lsqcurvefit (line 253)
[xCurrent,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
채택된 답변
추가 답변 (1개)
When xdata(i)=x(1) or x(3)=0, then beta(i) will be zero and your expression for F
F = x(2).*sinbeta.^2./beta.^2
is undefined.
Similarly, if xdata is being assigned the uint16 variable "a" in your a.mat file, then any operation xdata(i)-x(1) will evaluate to 0 when x(1)>xdata(i). My guess is that this is what's happening, in which case you should cast a to double precision.
댓글 수: 4
I now see that your xdata=1:1280
This means that xdata(600)=600. Since x(1)=600 at your initial point, this will give F(600)=0/0=NaN in your objective function.
Presumably you want F=0 when beta=0? If so, add some post-processing
F(beta==0)=0;
G Guerrer
2015년 8월 7일
G Guerrer
2015년 8월 7일
Matt J
2015년 8월 7일
Try this simple experiment at the command line.
>> beta=0; sin(beta)/beta
ans =
NaN
카테고리
도움말 센터 및 File Exchange에서 Linear Least Squares에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!