I get matlab error :Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
2 次查看(过去 30 天)
显示 更早的评论
Dear all, I am new to optimization toolbox and 'fmincon' function throws error message :'Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.' Please see the code below: Y is an array. F = @(x,xdata) x(1)*(exp(-x(2)*xdata))+x(3)*(exp(-x(4)*xdata)); pot_diff = abs(max(y) - min(y)); tau = 0.01*length(y); x0 = [0.02 20 0.04 10]; A = []; b = []; Aeq = []; beq = []; lb = []; ub = []; % lb = [0.1*pot_diff 0.3*tau 0.3*pot_diff 0.1*tau]; % ub = [0.6*pot_diff 0.8*tau 0.8*pot_diff 0.6*tau]; options = optimoptions(@fmincon,'Algorithm','interior-point','Display','off'); [x,fval,exitflag,output,lambda,grad,hessian] = fmincon(F,x0,A,b,Aeq,beq,lb,ub,@my_nlincon,options)
function [C,Ceq] = my_nlincon(x)
C(1) = x(3)-x(1); C(2) = x(2)-x(4); Ceq = []; return
The complete error message is : Error using @(x,xdata)x(1)*(exp(-x(2)*xdata))+x(3)*(exp(-x(4)*xdata)) Not enough input arguments. Error in fmincon (line 640) initVals.f = feval(funfcn{3},X,varargin{:}); Error in strt (line 113) [x,fval,exitflag,output,lambda,grad,hessian] = fmincon(F,x0,A,b,Aeq,beq,lb,ub,@my_nlincon,options) Caused by: Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
Please help me solve this error. I also have doubt on using fmincon for a equation having 4 parameters.
0 个评论
采纳的回答
Torsten
2017-7-27
1. Input vector for the objective function F is only x, not x and xdata.
2. I don't see that you define "xdata".
3. Since I suspect that "xdata" will be a vector, take care that F returns a scalar. As it stands, F returns a vector.
Best wishes
Torsten.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!