Failure in initial user-supplied objective function evaluation. LSQCURVEFIT cannot continue.

조회 수: 2 (최근 30일)
My code below generates the following error. I have been stuck at it and Im not sure why. It works for an exponential version.
x = load('depth-0.txt');
y = load('mean-0.txt');
F = @(p,x) (p(1) + p(2)*(x*x));
x0 = [-1 1];
[p,resnorm] = lsqcurvefit(F, x0, x, y);
estimate_x = 1:0.1:100;
estimate_y = (p(1) + p(2)*(estimate_x*estimate_x));
plot(estimate_x, estimate_y,'-','LineWidth',2);
Error using * Inner matrix dimensions must agree.
Error in @(p,x)(p(1)+p(2)*(x*x))
Error in lsqcurvefit (line 199) initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Caused by: Failure in initial user-supplied objective function evaluation. LSQCURVEFIT cannot continue.

채택된 답변

Walter Roberson
Walter Roberson 2017년 2월 7일
F = @(p,x) (p(1) + p(2).*(x.*x));
The parameter you are describing as x will be a matrix. The * operator in MATLAB is algebraic matrix multiplication from linear algebra, which requires that the number of columns of the array on the left hand side be equal to the number of rows of the array on the right hand side of the * operator. With x * x the only way that could happen is if x was square.
The .* operator is element-by-element multiplication.
  댓글 수: 2
RuiQi
RuiQi 2017년 2월 7일
Argh sorry I knew that. I tend to forget the simplest things when switching between programming languages.
shariq khan
shariq khan 2018년 11월 18일
x0 = [1,1,1e-9];
lb = [-inf,-inf,-inf];
ub = [inf,inf,inf];
fun = @(x) x(1) + x(2).*exp(-t.*x(3));
vmut_obtained = lsqcurvefit(fun,x0,t,vmut,lb,ub);
couldnt upload data set, as it is 1x157 vector
I get similar error for this function .any suggestion?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Nonlinear Least Squares (Curve Fitting)에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by