# Are my equations correct for a simple lithium ion battery model in Python?

I am trying to create a simple battery model in Python based on the RC circuit from, http://firsttimeprogrammer.blogspot.com/2015/07/electric-circuits-101-rc-and-rl-circuits.html. I have attached figures of what I would ideally want the output to look like using my equations.

I know battery modeling is a large subject, but I want to make a simple lithium ion battery model based off a RC circuit where I can decide when the battery charges and discharges.

I am wondering if my equations are correct for what I am trying to do (the equations are in the code below). Right now all my equations are independent and only rely on time, but I am wondering if the current and voltage across the capacitor equations for charging/discharging should somehow be dependent. I am not taking into account factors like heat, cycling, etc. This is supposed to be a simple model with just charging and discharging.

Below are some examples of plots I found that I would like my code output to look like. When the battery is "used" it discharges and the voltage level in the battery decreases, when the battery charges, you see the corresponding current and the voltage reaching its full capacity.

You will see in the code I have 3 equations that correspond to the "battery", which are for charging (#Charge Equations), and 3 equations for the "battery" that correspond to discharging (#Discharge Equations). These are the equations I am curious about.

import numpy as np
import matplotlib.pyplot as plt

plt.style.use('ggplot')

#capacitor (battery)
c = 100 * 10**(-6) #farad
#voltage source
vs = 5 #volts
#resistor
r = 2000 #ohms

#time
t = np.linspace(0,1,1000)

#Charge Equations
q = c*vs*(1-np.exp((-1/(r*c))*t)) #charge
i = (vs/r)*np.exp((-1/(r*c))*t) #battery current
vc = vs*(1-np.exp((-1/(r*c))*t)) #battery voltage

#Discharge Equations
qd = c*vs*(np.exp((-1/(r*c))*t)) #discharge
id = (vs/r)*np.exp((-1/(r*c))*t) #battery current
vd = vs*(np.exp((-1/(r*c))*t)) #battery voltage

plt.plot([0,t[-1]],[c*vs,c*vs],label='Charge peak')
plt.plot(t,q,label='Charge of the capacitor (C)')
plt.plot(t,i,label='Current (A)')
plt.plot(t,vc,label='Voltage across capacitor')

print('Tau',1/(r*c))
print('Peak current (A)',vs/r)

plt.xlabel('Time (s)')
plt.title('Battery')
plt.legend()
plt.show()


The code is not finished, however, when done the basic idea is that when I run the code, I can specify when I want the battery to charge and when I want it to discharge during a simulated amount of time.

To summarize, here are my main questions and concerns:

1. Are my equations correct for what I am trying to do?
2. Should the equations somehow be dependent on each other?
3. Should I be using a different set of equations when trying to simulate my lithium ion battery?

Any advice, or suggestions, would be greatly appreciated. If anything seems unclear, or needs further explaining, please let me know.

Sources for pictures

First picture: https://www.dnkpower.com/why-18650-battery-explode/

• They are not perfect, but they look correct. The battery charging is described very well here: batteryuniversity.com/learn/article/… – CFCBazar com Apr 24 '20 at 10:38
• It would be normal to stop CV charging at some percentage (probably not less than 10%) of the CC charge current rather than 0A. – user_1818839 Apr 24 '20 at 13:23
• The battery equivalent cct is not just a simple RC. How accurate do you want it? – Tony Stewart EE75 Jul 30 '20 at 14:18
• @TonyStewartSunnyskyguyEE75 I want to simulate large battery storage, most likely lithium ion. Something that can be charged with PV, and discharged. I want my simulation to be as simple as possible, but still allow me to calculate the available energy (watt-hour), voltage, and current going in and out of the battery at each time step in seconds. I am ignoring things such as, heat, degradation from cycling, etc. I think my biggest problem has been finding the correct circuit to simulate this with. I have come across 2RC circuit equivalent circuits, so maybe that may be the way to go. – W. Churchill Aug 1 '20 at 3:14
• Yes I have simulated the 2RC cct with other parts on Falstad. But lookup Peukert's Law – Tony Stewart EE75 Aug 3 '20 at 22:35