MATLAB Answers

Abm
0

Calculate the hourly battery capacity

Abm
さんによって質問されました 2019 年 6 月 14 日
最新アクティビティ Abm
さんによって コメントされました 2019 年 6 月 17 日
dpb
さんの 回答が採用されました
Hi guys,
I want to calculate the updated battery capacity after everyhour, I wrote som code to loop through the time and calculate the capacity based on the change in the battery energy level but I get unrealistic results, I get zero capacity all the time. It feels that it should be easy doing but since I am a beginner in Matlab, I cant really see where I am doing wrong. Therefor I am so thankful for any feedback and suggestion to alternative solution.
PS. the first part of the code is just to make you guys understand the different parameter.
Thanks in advance!
%% Reliability measurment:
%%% The idealized energy production from pv panels during hour t:
H_t=Dataclean_interpolated.SolarIrradiance;% The solariradiance at time t
G_STC=1000; %W/m^2, The solarirradiance at which the pv panels are rated- typically 1000 W/m^2
Z_B=13.8; % or 6.2 or 27.5 , depending on the design approach, this is the proportionality variable values for the battery
Z_Pv=0.35; % or 0.55 or 0.85, depending on the design approach, This is the proportionality variable values for the PV panels
R_pv=Z_Pv*daily_load_wh;% watthours, the pv panels rated capacity
R_B=Z_B*daily_load_wh; %Watthours, This is the battery rated capacity
P_t=(H_t./G_STC).*R_pv; % watthours, Ideal energy production of pv panels
%%% Next include the effect of component aging and losses:
A_pv= 0.80;% the end of life rating for Pv
A_B=A_pv; % the end of life rating for the battery
Eff_sys=0.85; % Combined effeciency, Effeciency for syste component other than battery and inverter included losses caused by dust pv panels mismatch, shading and cabel resistance
P_L_t=P_t.* A_pv.*Eff_sys; % the availabel energy from PV array during hour t that can be applied for useful purpose ( charging the battery or supply the load)
%%% Next, the net energy calculation:
I_t=Dataclean_interpolated.InverterEnergy;% The load in Wh
N_t=P_L_t-I_t;% net energy
%%% if N_t is positive, then the battery is charged during hour t,whereas negative
%%% N_t means the battery is discharged
%%% The change in battery energy level:
Eff_B_in=0.92;% the battery charge effeciency
Eff_B_out=0.92; % the battery discharge effeciency
for i=1:length(N_t)
if N_t(i)> 0
delta_B_t(i)=N_t(i)*Eff_B_in;
else
delta_B_t(i)=N_t(i)/Eff_B_out;
end
end
delta_B_t;
%%% The battery level increase or decrease according to the following :
Timelength=length(delta_B_t);
B_Energy_t=zeros(1,Timelength);
B_Capacity_t=zeros(1,Timelength);
B_Energy_t(1)=1;%initial battery state of charge assumed to be 100%
for i=2:Timelength
B_Energy_t(i)=B_Energy_t(i-1)+delta_B_t(i);
if B_Energy_t(i)>(R_B*A_B)
B_Capacity_t(i)=R_B*A_B;
if B_Energy_t(i)<(R_B*DOD)
B_Capacity_t(i)=R_B*DOD;
else
B_Capacity_t(i)=B_Energy_t(i);
end
end
end
B_Capacity_t;

  0 件のコメント

サインイン to comment.

2 件の回答

dpb
回答者: dpb
2019 年 6 月 14 日
 採用された回答

...
B_Energy_t(i)=B_Energy_t(i-1)+delta_B_t(i);
if B_Energy_t(i)>(R_B*A_B)
B_Capacity_t(i)=R_B*A_B;
if B_Energy_t(i)<(R_B*DOD)
B_Capacity_t(i)=R_B*DOD;
else
B_Capacity_t(i)=B_Energy_t(i);
end
end
...
Re-indenting your code structure to show the logic levels makes it easier to read the code---always a good practice. I personally use 2 spaces as the ideal compromise between visibility and code not getting pushed way off to the right but that's personal preference.
Note that you have the if B_Energy_t(i)<(R_B*DOD) clause entirely nested within the outer if for if B_Energy_t(i)>(R_B*DOD). Hence, that whole section is "dead code" in that it can never be executed.
You probably meant something like
...
...
B_Energy_t(i)=B_Energy_t(i-1)+delta_B_t(i);
if B_Energy_t(i)>(R_B*A_B)
B_Capacity_t(i)=R_B*A_B;
elseif B_Energy_t(i)<(R_B*DOD)
B_Capacity_t(i)=R_B*DOD;
else
B_Capacity_t(i)=B_Energy_t(i);
end
...

  0 件のコメント

サインイン to comment.


Steven Lord
回答者: Steven Lord
2019 年 6 月 14 日

We can determine the sizes of some of the variables you've defined in this code from what you've shown, but others we cannot. In particular, we know that A_B is a scalar (0.80, the same value as A_pv) but we don't know the sizes of R_B or DOD. R_B is the product of a variable we know is a scalar (Z_B) and a variable about which we know nothing (daily_load_wh.) My guess is that at least one of those variables is non-scalar.
Why is the size of the variables important? From the documentation page for the if keyword, "An expression is true when its result is nonempty and contains only nonzero elements (logical or real numeric). Otherwise, the expression is false."
So on this line of your code:
if B_Energy_t(i)>(R_B*A_B)
If R_B is a vector, B_Energy_t(i) must be greater than all the elements of R_B*A_B or the if statement's condition is not satisfied. The same holds for the following line of code, where B_Energy_t(i) must be less than all the elements of R_B*DOD:
if B_Energy_t(i)<(R_B*DOD)
If I had to speculate, I'd guess DOD is a scalar and R_B is a vector making R_B*A_B and R_B*DOD both vectors the same size as R_B.
You might need to index into R_B or you may need to call any around the expression so if is satisfied if the condition is satisfied for any of the elements in R_B, not all. Alternately the min and/or max functions may be able to help you avoid the if statements entirely.

  1 件のコメント

Abm
2019 年 6 月 17 日
Thank you Steven for feedback!
DOD= 0.50 and R_B=63381.82.

サインイン to comment.



Translated by