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)
c=[]
ceq=K_wrapper
end
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)
res=lsqcurvefit(obj,x0,xdata,ydata,lb,ub,A,b,Aeq,beq,nlcon);
Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.
"
how should i resilve this?
3 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!