Battery charging profile - Most efficient way of plotting

8 visualizzazioni (ultimi 30 giorni)
Hello,
I'm looking to plot the charging profile of an electric vehicle over 24 hrs based on randomly assigned arrival times T_Arr and SoC (state of charge). The battery charges constantly for the duration of the charge. T_Dur. The charging ends at T_End = T_Arr+T_Dur. I want to generate a series of rectangular profiles. I was wondering if there is better way of plotting the charge vs time of day
For my Y values containing the charge , I first create an array of zeros and subsequently later replace the zeroes with the charge values at T_Arr and T_End. For example the Y values for T_Arr = 10 and T_End = 13 should both be 5 . Since the battery charges at a constant rate, T=11,12 should also be 5. What's the most efficient way of doing this?
for i = 1:10000
z = randi(100);
Minutes = randi(60);
%Arrival times
if z <= 1.1
T_Arr = 0;
elseif z <= 1.2
T_Arr = 60;
elseif z <= 1.3
T_Arr = 120;
elseif z <= 2.2
T_Arr = 180;
elseif z <= 3.5
T_Arr = 240;
elseif z <= 5.5
T_Arr = 300;
elseif z <= 9.5
T_Arr = 360;
elseif z <= 14.1
T_Arr = 420;
elseif z <= 17.7
T_Arr = 480;
elseif z <= 21.1
T_Arr = 540;
elseif z <= 26
T_Arr = 600;
elseif z <= 32.9
T_Arr = 660;
elseif z <= 38.3
T_Arr = 720;
elseif z <= 43.4
T_Arr = 780;
elseif z <= 48.5
T_Arr = 840;
elseif z <= 55.2
T_Arr = 900;
elseif z <= 64.3
T_Arr = 960;
elseif z <= 74.4
T_Arr = 1020;
elseif z <= 81.5
T_Arr = 1080;
elseif z <= 88.3
T_Arr = 1140;
elseif z <= 92.6
T_Arr = 1200;
elseif z <= 96.7
T_Arr = 1260;
elseif z <= 99
T_Arr = 1320;
else
T_Arr = 1380;
end
T_Arr = T_Arr + Minutes;
T_Arr = T_Arr/60;
T_Arr = round(T_Arr);
z = randi(100);
SOC_End=1;
if z <= 5
SOC_Start = 0.2;
elseif z <= 15
SOC_Start = 0.3;
elseif z <= 35
SOC_Start = 0.4;
elseif z <= 65
SOC_Start = 0.5;
elseif z <= 85
SOC_Start = 0.6;
elseif z <= 95
SOC_Start = 0.7;
else
SOC_Start = 0.8;
end
%Calculation of the end time of the charging process
E_Char = E_Cap * (SOC_End-SOC_Start);
T_Dur = E_Char*T_Char;
T_End = T_Arr+T_Dur;
T_End = round(T_End);
n=T_End-T_Arr;
% 1 hr to 24 hr
Time_value=linspace(1,24,24);
%intially set all charge (Y) values to zero
Charge_value=zeros(1,24);
% replace charge values at T_Arr and T_end with E_Char
if n==1
Charge_value(T_Arr)=E_Char;
Charge_value(T_Arr+1)=E_Char;
Charge_value(T_End)=E_Char;
else
Charge_value(T_Arr)=E_Char;
Charge_value(T_Arr+n-1)=E_Char;
Charge_value(T_Arr+n)=E_Char;
Charge_value(T_End)=E_Char;
end
hold on
plot(Time_value,Charge_value,'-o')
end
  1 Commento
Andrew Cortez
Andrew Cortez il 28 Set 2020
Modificato: Andrew Cortez il 28 Set 2020
Hello, could you send me the updated code at andrewjohncortez@gmail.com
I'm trying to follow along and was not sure what E_Cap and T_Char values you used.
Thank you!

Accedi per commentare.

Risposte (1)

Gifari Zulkarnaen
Gifari Zulkarnaen il 16 Feb 2020
I have suggestion for your long repetitive elseif, try to use this instead:
z = randi(100);
zLim = [logspace(0,2,9) Inf]; % limit criteria for z
T_Arr_list = linspace(0,1380,10); % list of T_Arr for each z limit
T_Arr = T_Arr_list(find(zLim-z >= 0,1,'first'));
  3 Commenti
Gifari Zulkarnaen
Gifari Zulkarnaen il 16 Feb 2020
The logspace and linspace are just example, change it with your values.
zLim = [1.1 1.2 1.3 Inf]; % limit criteria for z, please input the complete set yourself, don't forget the Inf for last value
T_Arr_list = 0:60:1380; % list of T_Arr for each z limit
for i=1:10000
z = randi(100);
T_Arr = T_Arr_list(find(zLim-z >= 0,1,'first'));
end

Accedi per commentare.

Categorie

Scopri di più su Energy Production in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by