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

조회 수: 1 (최근 30일)
kam Pal
kam Pal 2021년 2월 15일
댓글: kam Pal 2021년 2월 15일
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에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by