Too many output arguments??? in nonlinear constraint function in ga

1 回表示 (過去 30 日間)
Khoo
Khoo 2013 年 8 月 22 日
This is my nonlinear constraint function in ga built-in function,
function ceq=nonlincon(z)
ceq=z(3).*exp(z(2).*(1-z(1)))-1;
I am curious i obtain the error message:
Error using nonlincon Too many output arguments.
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11) fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in constrValidate (line 22) [tmpCineq,tmpCeq] = nonlcon([Iterate.x Iterate.x]');
Error in gacommon (line 136) [LinearConstr, Iterate,nineqcstr,neqcstr,ncstr] = constrValidate(NonconFcn, ...
Error in ga (line 319) [x,fval,exitFlag,output,population,scores,FitnessFcn,nvars,Aineq,bineq,Aeq,beq,lb,ub, ...
Error in Runfile (line 21) est=ga(h,3,[],[],[],[],[0 0 0],[1.0 10.0 1.0],contraint,options);
Caused by: Failure in initial user-supplied nonlinear constraint function evaluation.
WHY it is like that, i have only one output so far... Thanks!
  1 件のコメント
David Sanchez
David Sanchez 2013 年 8 月 22 日
how are you calling your nonlincon function?

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 8 月 22 日
The non-linear constraint function is required to have two outputs, one for equality constraints and one for inequalities. If you do not wish to use one of the types of constraint, set the output for it to []
  2 件のコメント
Khoo
Khoo 2013 年 8 月 22 日
So how to write the code instead? Is it something like
function [[],ceq]=nonlinconst(x)
I have tried this, it doesn't work as well.
Khoo
Khoo 2013 年 8 月 22 日
Ok i got it,
function [c,ceq]=nonlinconst(x)
c=inequality;
ceq=[];
Thanks!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNonlinear Control についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by