Clear Filters
Clear Filters

genetic algorithm 'too many input arguments'

1 view (last 30 days)
I want to minimize a function with a constraint which has 8 inputs. The problem is I cannot call the by x(1), x(2),etc because they are generated in another program in each loop and thos variables are used in other places. Does anyone have suggestion?
  2 Comments
Walter Roberson
Walter Roberson on 1 Dec 2013
Please show your code attempt, and show how the functions are being generated.
Ali Meghdadi
Ali Meghdadi on 2 Dec 2013
Edited: Walter Roberson on 2 Dec 2013
this is my constraint:
function NLPS = LPS(Nwt, Nbat, Npv, tilt, TArray, KtArray, LArray, WindArray)
EBatMax = 6.936*2*Nbat;
EBatMin = 0.5*EBatMax;
Ebat = EBatMax;
NLPS = 0;
for i=1:8760
T = TArray(i);
Kt = KtArray(i);
L = LArray(i);
Wind = WindArray(i);
[B0, delta, w0, ws] = daily_beam(i,tilt);
Epv = out_PV(Kt, Npv, T, B0, tilt, delta, w0, ws);
Ewt = out_wt(Wind, Nwt);
Generate = Epv + Ewt;
[EBatNew, Gbat] = out_bat(Ebat, EBatMin, EBatMax, Generate, L);
Ebat = EBatNew;
Generate = Generate + Gbat;
Net = L - Generate*0.9;
if Net < 0
NLPS = NLPS + 1;
end
end
end
this is the function to be minimized:
C=cost(Nbat,Nwt,Npv)
the inputs of NLPS are generated in other functions. genetic is supposed to generate some numbers for Nbat,Npv,Nbat and tilt in a way that minimizes the cost and also satisfies the constraint function.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 2 Dec 2013
Something like,
constraint_function = @(x) LPS(x(1), x(2), x(3), tilt, TArray, KtArray, LArray, WindArray);
??
  2 Comments
Ali Meghdadi
Ali Meghdadi on 2 Dec 2013
yes exactly. I tried and I get 'too many input arguments". Do you have any idea what is wrong here?
Ali Meghdadi
Ali Meghdadi on 2 Dec 2013
I tried to simplify the issue optimizing this function `function z=f(x) f=(x(1)-2)^2+(x(2)-1)^2`. I input this in command window: [x fval]=ga(@f,2). But still I get same error!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!