How to fix iteration of one positive integer in an equation to update automatically in next index?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Shahab Khan
am 12 Dez. 2018
Kommentiert: Shahab Khan
am 12 Dez. 2018
Following is the code I am using:
Batt_Power = 45.5; % kW
Power = 108*1000; % kW
Journery_Time_Hrs = 0.8; %hrs
Battery_Capacity = 87; % Unit kWh Positive Intiger
Energy_Used = cumsum(Batt_Power * ((EnergyF)/3.6/1000000))/ (Power/1000); % Cumulative Energy
Energy_Regen = FC_Charging * Journery_Time_Hrs;
% Size of Arrays
EnergyF = 2241x1;
Energy_Used = 1x22401; % Unit kWh Cumulative Data
Energy_Regen = 1x22401; % Unit kWh Cumulative Data
I am using this equation to find battery state of charge.
Soc = Battery_Capacity - Energy_Used + Energy_Regen;
% size of Soc = 1000*1
This is suppose to give me battery state of charge. However, it does not provide correct answer.
I know why but I don't know how to fix it.
The problem originates from Battery_Capacity.
Expected Correct Result:
This is the correct result I shall get if I use Soc equation correctly. The Battery Capacity must automaticaly update it self in next index of Battery_Capacity till end of the array.
87 - 0.5 + 0.3 = 86.2
86.2 - 0.7 + 0.4 = 85.9
85.9 - 1.4 + 0.5 = 85
Wrong Result From Code:
But, I am getting this kind of result, Battery_Capacity is always 87 till the end of array.
87 - 0.5 + 0.3 = 86.8
87 - 0.7 + 0.4 = 86.7
87 - 1.4 + 0.5 = 86.1
Can any one please sugguest how can I fix this.
Thanks
7 Kommentare
KSSV
am 12 Dez. 2018
I think after the formula for soc you need to update :
Battery_Capacity = soc ;
Akzeptierte Antwort
Cris LaPierre
am 12 Dez. 2018
Bearbeitet: Cris LaPierre
am 12 Dez. 2018
You are not updating the value of Battery_Capacity (you know that). How are you calculating SOC? All at once or inside a for loop? I think it would have to be in a loop to work because values on Soc(n+1) depend on the calculation performed in Soc(n). Taking KSSV's suggestion from above:
for idx = 1:length(Energy_Used)
...
Soc(idx) = Battery_Capacity - Energy_Used(idx) + Energy_Regen(idx);
Battery_Capacity = Soc(idx);
end
3 Kommentare
Cris LaPierre
am 12 Dez. 2018
Using the variables provided in your mat file, the difference between these two approaches for calculating Soc is <1e-8
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spline Postprocessing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!