Find minimum of variable by altereing two variables.
1 次查看(过去 30 天)
显示 更早的评论
Hello!
I'm simulating an energy system and trying to minimize a variable by altering battery size and level of power consumption in an if loop. At the time I'm just altering the battery and level of power manually, but is there a way to alter them automatically to find a minimum?
See code if anything is unclear. It is "E_bat_max" and "Allowed_summer" I'm altering to minimize "overload".
for j = 2061:24:2880
for i = (j):(j+23)
E_load2(i) = E_load(i)+EV_load(i)-E_pv2(i);
if E_load2(i) < Allowed_summer
if E_bat < E_bat_max
charge = min(P_bat, (Allowed_summer-E_load2(i)));
E_bat = min(E_bat + charge*eff, E_bat_max);
E_load2(i) = E_load2(i)+charge;
E_bat2(i) = E_bat;
elseif E_bat == E_bat_max
E_bat2(i) = E_bat;
end
end
if E_load2(i) > Allowed_summer
if (0 < E_bat) && (E_bat <= E_bat_max)
charge = min([P_bat, (E_load2(i)-Allowed_summer), E_bat]);
E_bat = E_bat-charge;
E_load2(i) = E_load2(i) - charge;
E_bat2(i) = E_bat;
end
end
end
end
for i = time
if E_load2(i) ~= Allowed_summer
overload = overload +1;
end
end
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!