Effacer les filtres
Effacer les filtres

non linear optimization returns a "Too many output arguments."

3 vues (au cours des 30 derniers jours)
Amani mahdy
Amani mahdy le 17 Août 2016
Commenté : Matt J le 17 Août 2016
Hello all,
I am using the genetic algorithm to solve a MINL problem, I am calling the non-linear-constraints as:
nonlcon = @non_linear_constraint_all_ga;
I have around 60 constraints, so nonlcon supposes to be a vector of 60 elements..
the called function is as follows :
function c1=non_linear_constraint_all_ga(x)
[~ ,c1,~]=objective_finction_and_non_linear_contsrains_ga(x);
end
i am taking only the second output from the BIG function "objective_finction_and_non_linear_contsrains_ga"
function [y ,c1,ceq1]=objective_finction_and_non_linear_contsrains_ga(x)
for (j=1 :Ns+2:(2+Ns)*Nc)
for (i=0:Ns-1)
k=i+1;
c1(1,m) = x(1,j+2+i).*sqrt(w((i+k),1)-x(1,j));
m=m+1;
end
end
end
I keep getting the following error :
Too many output arguments.
Caused by:
Failure in initial user-supplied nonlinear constraint function evaluation.
Any idea ?
best regards,

Réponse acceptée

Matt J
Matt J le 17 Août 2016
Modifié(e) : Matt J le 17 Août 2016
The nonlinear constraint function must be equipped to return 2 arguments if requested, one for inequality and one for equality constraints.
function [c1,ceq1]=non_linear_constraint_all_ga(x)
[~ ,c1,ceq1]=objective_finction_and_non_linear_contsrains_ga(x);
end
  2 commentaires
Amani mahdy
Amani mahdy le 17 Août 2016
Thank you so much, IT WORKS =D
but at the end, nonlcon will equal to c1 since it is the first output , isnt it ?
Matt J
Matt J le 17 Août 2016
No, ga will always request both c1 and ceq1 as outputs. However, if it sees that ceq1 is empty, it will realize that you have no equality constraints.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by