-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbattery.m
30 lines (18 loc) · 635 Bytes
/
battery.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function [soc, pout, Ah_cur_con, K] = battery( pbnew, pbold, pbmax)
% nb=0.9; %efficiency
nb=1; %efficiency
dT=1; %1 hour
Vb=12; %inital Voltage
Ahinit=25; %inital Ampere-hours
K = pbmax/(Vb*Ahinit*dT/nb);% total batteries
Ahinit= Ahinit*K;
Ah_cur_con = (pbnew/pbmax)*Ahinit;
Ah_con = (sum(pbold)/pbmax)*Ahinit;
Ah_remain = (Ahinit)-Ah_con;
soc = (Ah_remain-Ah_cur_con)/(Ahinit);
pout(soc>=0) = (Vb*(Ah_cur_con));
pout(soc>1) = -(Vb*(Ah_con));
pout(soc<0) = 0;
soc(soc<0) = (Ah_remain)/(Ahinit);
soc(soc>1) = 1;
end