Not Enough Input Arguments using GA
Show older comments
I'm trying to minimize a function using GA with some of the variables as integers, with a few linear inequalities, linear equalities, and a bunch of nonlinear inequalities, keep getting the error:
Not enough input arguments.
Error in project>nonlinear (line 30)
h=x(1);
Error in project (line 13)
[x, fval, exitflag] = ga(@zfun,10,A,b,Aeq,beq,lb,ub,nonlinear,intcon,options)
Here's my full code:
clc; clear; %1=h 2=ds 3=db 4=n 5=s 6=Ss 7=L 8=d 9=c 10=dv
A=[0 0 1.4 0 -1 0 0 0 0 0; 0 0 0 0 0 0 0 0.9 0 -1; 0.72 0 0 0 0 0 0 0 0 -1;
0 0 0 0 0 1 0 0 0 -0.7; -1 1 0.5 0 0 0 0 1 0 0; 0 0 0 0 0 0 1 0 0 0; 0 0 0 0 0 0 0 0 1 0];
%bar spacing; bar spacing; bar spacing; define dv; define dv; max Ss;
%define d
b=[0; 0; 0; 0; -75; 0; 0];
lb=[0 0 0 0 30 0 0 0 0 0];
ub=[inf inf inf inf inf 600 inf inf inf inf];
intcon=[1 2 3 4 5 6 7 9];
options=[];
[x, fval, exitflag] = ga(@zfun,10,A,b,[],[],lb,ub,nonlinear,intcon,options)
function z = zfun(x)
h=x(1);
ds=x(2);
db=x(3);
n=x(4);
s=x(5);
Ss=x(6);
L=x(7);
d=x(8);
c=x(9);
dv=x(10);
z= 16000*h + 500*0.000007854*db^2 +500*0.007854*ds^2*(2*h/1000+8)/Ss;
end
function [c] = nonlinear(x)
h=x(1);
ds=x(2);
db=x(3);
n=x(4);
s=x(5);
Ss=x(6);
L=x(7);
d=x(8);
c=x(9);
dv=x(10);
c(1) = 3000*h + 187.5 - 267*n*d*db^2 + 0.5714*n^2*db^4; %Mr>Mf
c(2) = 21.909*h - 0.7854*db^2; %Asmin
c(3) = 16*h - 0.7854*db^2; %Asmin for Ag
c(4) = 0.0021397*n*db^2/d - 0.5; %a/d
c(5) = 1164*h + 72.75 - 762.653*ds^2*dv/Ss - 5126.68*dv; %Vs+Vc>Vfdv
c(6) = 5126.68*dv + 762.653*ds^2*x(11)/Ss - 39000*dv; %max Vr
c(7) = 6.573*Ss - 1.5708*ds^2; %min Av
c(8) = Ss - 0.239*ds^2; %max Ss
c(9) = (h-d)^0.66666/n^0.333333 - 4.96063; %crack control
c(10) = n*db + (n-1)*s + 2*ds - 7850; %bar spacing req
end
Thanks in advance.
EDIT: Learned I can't use intcon with equality constraints, updated my code but still have same error.
Answers (1)
Walter Roberson
on 7 Apr 2019
0 votes
Your call to ga needs to use @nonlinear rather than nonlinear
4 Comments
Monish Lad
on 7 Apr 2019
Walter Roberson
on 7 Apr 2019
The nonlinear constraints function must return two outputs, one for the nonlinear inequalities, and one for the nonlinear equalities. If you do not have any nonlinear equality constraints, return [] for the second output.
Monish Lad
on 7 Apr 2019
Walter Roberson
on 7 Apr 2019
Your non-linear constraints function needs a number of additional inputs.
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!