Filter löschen
Filter löschen

genetic algorithm 'too many input arguments'

1 Ansicht (letzte 30 Tage)
Ali Meghdadi
Ali Meghdadi am 1 Dez. 2013
Kommentiert: Ali Meghdadi am 2 Dez. 2013
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 Kommentare
Walter Roberson
Walter Roberson am 1 Dez. 2013
Please show your code attempt, and show how the functions are being generated.
Ali Meghdadi
Ali Meghdadi am 2 Dez. 2013
Bearbeitet: Walter Roberson am 2 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 2 Dez. 2013
Something like,
constraint_function = @(x) LPS(x(1), x(2), x(3), tilt, TArray, KtArray, LArray, WindArray);
??
  2 Kommentare
Ali Meghdadi
Ali Meghdadi am 2 Dez. 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 am 2 Dez. 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!

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by