필터 지우기
필터 지우기

genetic algorithm 'too many input arguments'

조회 수: 1 (최근 30일)
Ali Meghdadi
Ali Meghdadi 2013년 12월 1일
댓글: Ali Meghdadi 2013년 12월 2일
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
Walter Roberson
Walter Roberson 2013년 12월 1일
Please show your code attempt, and show how the functions are being generated.
Ali Meghdadi
Ali Meghdadi 2013년 12월 2일
편집: Walter Roberson 2013년 12월 2일
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.

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

답변 (1개)

Walter Roberson
Walter Roberson 2013년 12월 2일
Something like,
constraint_function = @(x) LPS(x(1), x(2), x(3), tilt, TArray, KtArray, LArray, WindArray);
??
  댓글 수: 2
Ali Meghdadi
Ali Meghdadi 2013년 12월 2일
yes exactly. I tried and I get 'too many input arguments". Do you have any idea what is wrong here?
Ali Meghdadi
Ali Meghdadi 2013년 12월 2일
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!

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

카테고리

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