Error in Genetic Algorithm: Input arguments to function include colon operator. To input the colon character, use ':' instead.

11 views (last 30 days)
I'm trying to run GA for a structural problem and I'm ending up with the error:
"Input arguments to function include colon operator. To input the colon character, use ':' instead."
I'm not able to find where the problem is. This is my code:
function C = fitnessmin(x)
%%constatns
q = 33e4;
H = 5;
g = 9.8;
L = 30;
DI = 2700;
DS = 2700;
ES = 70e9;
FSIbeam = 270e6;
FSSupport = 170e6;
cIbeam = 2.05;
cSupport = 2.05;
%%Mass
%%Ibeams
MIbeam = (2*x(1)*x(3) + (x(2) - 2*x(3))*x(3))*L*DI*x(6);
%%Support
MSupport = x(4)*x(5)*H*DS;
%%function
C = cIbeam*MIbeam + cSupport*MSupport;
end
function [c, ceq] = constraintmin(x)
%%constatns
L = 30;
q = 33e4;
H = 5;
g = 9.8;
DI = 2700;
DS = 2700;
ES = 70e9;
FSIbeam = 270e6;
FSSupport = 170e6;
%%Mass
%%Ibeams
MIbeam = (2*x(1)*x(3) + (x(2) - 2*x(3))*x(3))*L*DI*x(6);
%%Support
MSupport = x(4)*x(5)*H*DS;
%%Equations
MOIIbeam = (((x(2) - 2*x(3))^3)*x(3)/12) + 2*(((x(3)^3)/12) + x(3)*x(1)*((x(2)/2) - (x(3)/2))^2);
SIbeam = (q*((L/2)^2) + MIbeam*(L/4)*g)*(x(2)/2)/(8*MOIIbeam*x(6));
SSIbeam = (MIbeam*g + q*L)/(4*x(6)*(2*x(1)*x(3)) + (x(2) - 2*x(3))*x(3));
Pcrit = (pi*pi)*ES*min(((x(4)^3)*x(5)/12), (x(4)*(x(5)^3)/12));
Papplied = MIbeam*g + q*L/(2);
SSupport = Papplied/(x(4)*x(5))
%%Function
c = [SIbeam - FSIbeam; SSIbeam - FSIbeam; Papplied - Pcrit; SSupport - FSSupport];
ceq = [];
end
clear
clc
objectivefunction = @fitnessmin;
nvars = 6;
lb = [0 0 0 0 0 1];
ub = [1 1 1 1 1 4];
constraintfunction = @constraintmin;
[x,fval] = ga(objectivefunction, nvars, [], [], [], [], lb, ub, [], constraintfunction)
Any help is appreciated. Thanks!

Accepted Answer

Walter Roberson
Walter Roberson on 8 Apr 2018
The [] before constraintfun should not be there in the ga call. After lower bound is nonlinear constraint, and after that would be integer constraint (optional) and then options (optional) -- if both appear it must be in that order.
If you fix that then you will still have problems. In your constraint you define SSupport = Papplied / (x(4)*x(5)) . If either x(4) or x(5) are zero, then that is a division by 0 which leads to infinity which is not a permitted output from a constraint function. Your lower bounds are both 0 for x(4) and x(5) so it is possible for either or both of them to be 0.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!