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

조회 수: 9 (최근 30일)
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!

채택된 답변

Walter Roberson
Walter Roberson 2018년 4월 8일
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.
  댓글 수: 1
Praneeth Arcot
Praneeth Arcot 2018년 4월 8일
Yes thank you! I just found out that seconds ago. And I did change the bounds to make sure the values doesn't go inf. Cheers!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by