Clear Filters
Clear Filters

Find minimum of variable by altereing two variables.

3 views (last 30 days)
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

Answers (0)

Community Treasure Hunt

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

Start Hunting!