Trying to do a non linear fit under non linear constraints using lsqcurvefit: constraint needs more input

1 次查看(过去 30 天)
I am trying to do a non linear fit under non linear constraints using lsqcurvefit.
the objective function looks like this: obj=@(x,xdata) (calculations using x(1), x(2),x(3),xdata)
the non linear constraint condition has the form K=@(x,xdata,ydata,otherdata1) (calculations using x(1),x(2),x(3),xdata,ydata,otherdata1)
the nlcon (constraint argument) in lsqcurvefit takes only x as input (so to be able to pass K to nlcon, i have created a wrapper so that the K_wrapper facilitates passing the extra arguments into nlcon)
it should have the form:
function [c,ceq]=nlcon(x)
i ran nlcon separately and it works, which would mean that the wrapper functions work
i ran lsqcurvefit without the constraint condition and it works
The problem: as soon as i couple constraint and lsqcurvefit together, i get an error saying that
"Error using TopLevelScript>@(x,xdata) obj(x,xdata)
Too many input arguments.
Error in lsqcurvefit (line 225)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in TopLevelScript (line 45)
Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.
how should i resilve this?
  3 个评论
Torsten 2023-6-5
编辑:Torsten 2023-6-5
Your code is incomplete.
Test it here before posting using the code formatting and the green arrow in the menue to execute it.
We don't know "data.mat" and "calculate_sec_der".


回答(0 个)


Help CenterFile 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!

Translated by