MATLAB: Dose who know about Optimization with Summation objective function

cost functionMATLABminlpobjective-functionoptimizationschedulingtime series

Hello, I want make objective function for 24-h Charging / Discharging scheduling.
์บก์ฒ˜.JPG
So, I made like this
for 1:24
for 1:5
fun = a*P_char*C_cost1 - (1-a)P_dischar*C_cost2 %% a=charging signal, P = charging discharging power, C = charging discharging cost
end
end
but this function didn't consider other times cost, they just think current time step only.
How can I fix my function? Plz help me. thank you ๐Ÿ™‚

Best Answer

Maybe you should update fun to remember the entire sum, not just the final one. And maybe you should name your indices.
fun = optimexpr;
for i = 1:24
for j = 1:5
fun = fun + a(i)*P_char(i)*C_cost1(j) - (1-a(i))*P_dischar(i)*C_cost2(j) %% a=charging signal, P = charging discharging power, C = charging discharging cost
end
end
I may have messed up the i and j indices, but I hope that you get the idea. You could probably create the expression without any loops, too, and it would be more efficient to do so. See Expressions for Objective Functions.
Alan Weiss
MATLAB mathematical toolbox documentation