genetic algorithm 'too many input arguments'

6 visualizaciones (últimos 30 días)
Ali Meghdadi
Ali Meghdadi el 1 de Dic. de 2013
Comentada: Ali Meghdadi el 2 de Dic. de 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 comentarios
Walter Roberson
Walter Roberson el 1 de Dic. de 2013
Please show your code attempt, and show how the functions are being generated.
Ali Meghdadi
Ali Meghdadi el 2 de Dic. de 2013
Editada: Walter Roberson el 2 de Dic. de 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.

Iniciar sesión para comentar.

Respuestas (1)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Genetic Algorithm en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by