nonlcon : Too many input arguments.

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 comentarios

Torsten
Torsten el 24 de Nov. de 2015
You will have to show us your function with name "Constrain".
Best wishes
Torsten.
Ali T
Ali T el 24 de Nov. de 2015
The Constrain function is not like what other simple functions. Because of sizing component which runs with ADVISOR is implemented, it may sounds weird to you. Anyway, I bring me code down there:
function Con=Constrain(x)
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

Iniciar sesión para comentar.

 Respuesta aceptada

Alan Weiss
Alan Weiss el 24 de Nov. de 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 comentario

Ali T
Ali T el 24 de Nov. de 2015
Editada: Ali T el 24 de Nov. de 2015
Marvelous, that worked... amazing, thank you. Unfortunately I am not convinced why do I have to use con=[] and coneq=[] ??? When I ran my code, something new error pops up... Could you please help me solving this error too???
Error in adv_no_gui case {accel_test}:
Index exceeds matrix dimensions.
Attempt to reference field of non-structure array.
Error in Constrain (line 11)
accel_1 = resp.accel.times(1) ;
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(@Objective,X0,[],[],[],[],LB,UB,@Constrain,options)
Caused by:
Failure in initial user-supplied nonlinear constraint function evaluation.
PATTERNSEARCH cannot continue.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 24 de Nov. de 2015

Editada:

el 24 de Nov. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by