Created
August 28, 2015 18:50
-
-
Save mick001/52466504274e255a7720 to your computer and use it in GitHub Desktop.
RC RL circuits, a Python simulation, part 2. Full article at http://www.firsttimeprogrammer.blogspot.com/2015/07/electric-circuits-101-rc-and-rl-circuits.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
plt.style.use('ggplot') | |
c = 100 * 10**(-6) | |
v = 5 | |
r = 2000 | |
t = np.linspace(0,1,1000) | |
q = c*v*(1-np.exp((-1/(r*c))*t)) | |
i = (v/r)*np.exp((-1/(r*c))*t) | |
plt.plot([0,t[-1]],[c*v,c*v],label='Charge peak') | |
plt.plot(t,q,label='Charge of the capacitor (C)') | |
plt.plot(t,i,label='Current (A)') | |
print('Tau',1/(r*c)) | |
print('Peak current (A)',v/r) | |
plt.xlabel('Time (s)') | |
plt.title('RC circuit') | |
plt.legend() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment