How could I develop code to repeat evaluating these equations correctly?
1 view (last 30 days)
Show older comments
I need to code the equations below in my MATLAB code. The decision variable is P_bat and I need to repeat the calculations for loop = 1: T and for counter = 1:100
Battery pack
Discharging mode: C_bat(t+1) = max{ (C_bat(t) - P_bat(t)*delta_t/eta_d_bat), C_bat_min} for t=1,2...T (Equation 1)
Charging mode: C_bat(t+1) = min{ (C_bat(t) + P_bat(t)*delta_t*eta_c_bat), C_bat_max} for t=1,2...T (Equation 2)
Battery constraints
P_bat_min(t) <= P_bat(t) <= P_bat_max(t) (Equation 3)
where, P_bat_max(t) = min{P_bat_max, (C_bat(t) - C_bat_min)*eta_d_bat/delta_t} for t=1,2...T (Equation 4)
P_bat_min(t) = max{P_bat_min, (C_bat(t) - C_bat_max)*1/eta_c_bat*delta_t} for t=1,2...T (Equation 5)
SOC_bat(t) = C_bat(t)/C_bat_max (Equation 6)
SOC_bat_min<=SOC_bat(t)<=SOC_bat_max (Equation 7)
Here, P (power), C(capacity), eta(discharge/charge efficiencies), delta_t is the time step and all minimum and maximum quanities are defined earlier.
I started it as follows and I am not sure if I do it correct. If I use (T-loop) for delta_t in Equations 4 and 5, the answer is undefined when T=loop. I hope there should be a correct way in representing these in the code.
So, could someone please assist me to develop the code to represnt above equations? Should you need any more details, please let me know.
for loop: 1:T % where T=total time in hours
for counter: 1:100
C_bat(counter)= C_bat_max; % Battery maximum size
% Battery discharging
C_bat(counter+1)=C_ bat(counter)-((T-loop)*P_ bat(counter))/eta_d_bat;
% Battery charging
C_bat(counter+1) = C_ bat(counter)+((T-loop)*P_ bat(counter)*eta_c_bat);
2 Comments
John D'Errico
on 15 Feb 2021
Edited: John D'Errico
on 15 Feb 2021
I'd start by learning MATLAB syntax.
Not this:
for counter: 1:100
But this:
for counter = 1:100
However, it looks like your real problem was in understanding how to form the boundary conditions. And it seems like you are the one who knows what you want to do there.
Answers (0)
See Also
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!