nonlinear constrain error must return real value
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello! When trying to solve an optimization problem( linear and nonlinear constrains) using the ga function it returns the following error:
>> [x,fval] = ga(ObjectiveFunction,nvars,[],[],Aeq,Beq,lb,ub,ConstraintFunction)
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, ...
My non linear constrains are:
function [C,Ceq] = simple_constraint(x)
Ceq=[x(1)*70+x(8)*x(12)-x(3)*x(9);
x(2)*70+x(7)*x(11)-x(4)*x(10);
120-x(3)*(x(11)-x(9));
120-x(16)*0.2*x(13);
17.5-x(4)*(x(12)-x(10));
17.5-x(17)*0.5*x(14);
90-x(18)*0.5*x(15);
x(13)-((90-x(9))-(150-x(11)))/(log(abs((90-x(9))/(150-x(11)))));
x(14)-((264-x(10))-(264-x(12)))/(log(abs((264-x(10))/(264-x(12)))));
x(15)-((264-70)-(264-100))/(log(abs((264-70)/(264-100))))];
C=[];
end
And my function for minimizing is :
function y = simple_fitness(x)
y=5750*(x(16)^0.59+x(17)^0.59+x(18)^0.59);
end
We tried using the dbstop if error and in the c vector there was a NaN value (we think that is a problem in the 9th nonlean equality constrain, or do the c and ceq equality vectors don't connect?).
Thanks beforehand!
2 comentarios
Respuestas (1)
Star Strider
el 12 de Dic. de 2018
The expression beginning with ‘x(13)’ contains a log argument that could become negative if ‘x(11)’ is greater than 150, and similarly, ‘x(14)’ contains a log argument that could become negative if ‘x(12)’ is greater than 264. Logarithms of negative numbers are complex. Constraining these parameters in the ‘ub’ vector could be one solution, although since I do not know in what order the constraints are checked, might not prevent the error.
To illustrate:
log(abs((90-x(9))/(150-x(11))))
log(abs((264-x(10))/(264-x(12))))
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!