GA using arrays in objective function
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
Can anyone assist with how to get my GA to stop throwing errors.
If you have an example on how to use an array in a GA that would be much appreciated.
I am trying to pass the X value of the GA, a defined value, and three arrays into a function, mincost. The PV array and the battery are 5 x 1 and are independent arrays, but eleccostla3 is a 5 * 5. Each column in eleccostla3 references the value in the PV array, and each row references the battery array. The sum of these values should be the "fval" of the GA.
How do I set x as an integer and remove the "for loop" and actually use the GA.
This is the code I have:
mincostx = 1;
pvpriceinvonly = [1; 2; 3; 4; 5];
battery = [6; 7; 8; 9; 10];
eleccost = [7 8 9 10 11; 8 9 10 11 12; 9 10 11 12 13; 10 11 12 13 14; 11 12 13 14 15];
nvars = 6 ;
f = @(x)objpv(x, mincostx, pvpriceinvonly, battery, eleccost);
IntCon = [1 5];
[x fval] = ga(f,nvars, [], [], [], [], [], [], [], IntCon, []); %ga(fun,nvars,A,b,[],[],lb,ub,nonlcon,IntCon,options)
function mincost = objpv(x, mincostx, pvpriceinvonly, battery, eleccost)
mincostla = [];
for a = 1:5
for b = 1:5
Maintenance = (mincostx + pvpriceinvonly(a) * 0.05 * (1/(1.07)^20) * 20);
Capitalla = mincostx + pvpriceinvonly(a) + battery(b);
Elec = eleccost(a,b);
mincostla = (Capitalla + Maintenance + Elec);
mincost = min(mincostla);
end
end
end
Thanks.
댓글 수: 2
Alan Weiss
2021년 1월 20일
We cannot run this code because we don't have the objpv function. Please give us the full copy-pasted errors thrown from MATLAB so that we have a chance of understanding what you are seeing.
Alan Weiss
MATLAB mathematical toolbox documentation
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Genetic Algorithm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!