import numpy as np
from sympy import *
from IPython.display import *
import matplotlib.pyplot as plt
%matplotlib inline
init_printing(use_latex=True)
var('a b t k C1')
u = Function("u")(t)
de = Eq(u+u.diff(t) * k)
des = dsolve(de,u).subs(C1,0)
f = Lambda((t,k,a,b),(a-b) * des.rhs + b)
fig = plt.gcf()
fig.set_size_inches(8,5)
x = np.linspace(0,5,100)
plt.grid(True)
plt.xlabel('Time t seconds',fontsize=12)
plt.ylabel('Voltage',fontsize=12)
plt.title('R-C circuit decay profile',fontsize=16)
r = 10000 # resistor value Ω
c = 100e-6 # capacitor value farads
plt.text(2.1,7,'R = %.1f $\Omega$' % r,fontsize=14)
plt.text(2.1,6.3,'C = %.1f $\mu$f' % (c * 1e6),fontsize=14)
plt.plot(x,[f(t,r * c,0,10) for t in x],color='#008000')
plt.show()