how can i solve "Error using constrValidate" in genetic algorithm?

I'm trying to minimaze a non linear function with non linear costraints with a ga (i have attached the files with the functions), but whenever i run the code i have the following errors:
Error using constrValidate (line 59)
Constraint function must return real value.
Error in gacommon (line 125)
[LinearConstr, Iterate,nineqcstr,neqcstr,ncstr] = constrValidate(NonconFcn, ...
Error in ga (line 363)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, ...
Error in main (line 28)
[x, fval] = ga(ObjFcn,nvars,A, b, Aeq, beq, [], [], CostraintFunction);
How can i fix that?
Thanks for helping

1 个评论

This line in the error message is highly suggestive:
Constraint function must return real value.
Have you verified whether it is returning a real value? A good way to trap non-real values is to set a conditional breakpoint in the constraint function.

请先登录,再进行评论。

 采纳的回答

You have no upper or lower bounds, so all of your variables are permitted to be 0. In your constraint function, you divide by x(13) through x(18), so if any of those are 0 you get a division by 0, which leads to either +/- inf or to nan (you generate both.)
If you have no bounds, then your constraint function better be able to handle the all-zero input vector.
c=[0,000898*x(1)+0,000837*x(1)/x(13)-450;
What is the point of returning a column of 0's, and what is the point of adding 0 to the second column ? The above is the same as
c=[0, 000898*x(1)+0, 000837*x(1)/x(13)-450;
I have to wonder whether you intended decimal places instead of commas,
c=[0.000898*x(1)+0.000837*x(1)/x(13)-450;

更多回答(0 个)

类别

产品

Community Treasure Hunt

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

Start Hunting!

Translated by