How could I develop code to repeat evaluating these equations correctly?

1 次查看(过去 30 天)
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 个评论
John D'Errico
John D'Errico 2021-2-15
编辑:John D'Errico 2021-2-15
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.
kam Pal
kam Pal 2021-2-15
Thank you for highlighting the basic error that I've done.It's a typo. If I do it as I've done below, when T=loop in Equations 4 and 5, the answer is undefined.
for loop = 1:T % where T=total time in hours
for counter = 1:100
C_bat(counter) = C_bat_max; % Battery maximum size
C_bat(counter+1) = C_bat(counter)-((T-loop)*P_bat(counter))/eta_d_bat; % Battery discharging
C_bat(counter+1) = C_bat(counter)+((T-loop)*P_bat(counter)*eta_c_bat); % Battery charging
P_bat_max(counter)=(C_bat(counter)-C_bat_min)*eta_d_bat)/(T-loop); % Equation 4
P_bat_min(counter)=(C_bat(counter)-C_bat_max)/(eta_c_bat*(T-loop)); % Equation 5
if P_bat(counter)>P_bat_max(counter) % Checking upper and lower bounds
P_bat(counter)=P_bat_max(counter);
end
if P_bat(counter)<P_bat_min(counter)
P_bat(counter)=P_bat_min(counter);
end
end
end
Could you please guide me to correct this? I do appreciate your support in this.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by