nonlcon : Too many input arguments.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi friends, I have a problem with optimization algorithm like GA, fmincon and patternsearch. When I try to add constrain to my problem error below appear:
Error using Constrain
Too many output arguments.
Error in poptimfcnchk (line 58)
[cineq,ceq] = feval(nonlcon,reshapeinput(Xin,X),conFcnArg{:});
Error in patternsearch (line 343)
[Iterate,OUTPUT.funccount] = poptimfcnchk(FUN,nonlcon,initialX,Iterate, ...
Error in Main (line 30)
[x,Fval,exitFlag,output]=patternsearch(@(x)
Objective(x),X0,[],[],[],[],LB,UB,@Constrain,options)
Caused by:
Failure in initial user-supplied nonlinear constraint function evaluation.
PATTERNSEARCH cannot continue.
However, when I omit the constrain from optimization it works very well. After adding adding constrain to my problem this error occur. Could anyone help???
Thanks.
2 Kommentare
Torsten
am 24 Nov. 2015
You will have to show us your function with name "Constrain".
Best wishes
Torsten.
Akzeptierte Antwort
Alan Weiss
am 24 Nov. 2015
To quote the documentation on nonlinear constraints, "Nonlinear constraint functions must return both c and ceq, the inequality and equality constraint functions, even if they do not both exist. Return empty [] for a nonexistent constraint."
In other words, you need to rewrite your constraint function as follows, assuming your existing constraints are inequality rather than equality constraints:
function [Con,coneq] = Constrain(x)
Con = [];
coneq = [];
input.accel.param = {'spds','max_speed_bool'} ;
input.accel.value = {[0 37.28]};%;37.28 55.9234]} ;
[error, resp] = adv_no_gui('accel_test',input) ;
accel_1 = resp.accel.times(1) ;
MaxSpeed = resp.accel.max_speed*1.60934 ;
if ~error
Con=[accel_1/10-1;1-MaxSpeed/100];
end
Alan Weiss
MATLAB mathematical toolbox documentation
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Direct Search finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!