# charging of capacitor

\begin{equation}
\frac{Q}{C}+R\frac{dQ}{dt}=V
\end{equation}

\begin{equation}
\frac{dQ}{dt}=\frac{V}{R}-\frac{Q}{CR}
\end{equation}


```python
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
```


```python
# function that returns dy/dt
def model(y,t,C,R,V):
    dydt = V/R-y/(C*R)
    return dydt
```


```python
V=10 #V
C=1e-6 #F
R1=100 #ohm
R2 = 200
R3=400
```


```python
# time points
t = np.arange(0,0.002,0.0001) #
```


```python
# Charging
# initial condition
y0 = 0
y1 = odeint(model,y0,t,args=(C,R1,V))
y2 = odeint(model,y0,t,args=(C,R2,V))
y3 = odeint(model,y0,t,args=(C,R3,V,))

# plot results
plt.plot(t,y1,'r-',linewidth=2,label='R1=100$\Omega$')
plt.plot(t,y2,'b--',linewidth=2,label='R2=200$\Omega$')
plt.plot(t,y3,'g:',linewidth=2,label='R3=300$\Omega$')
plt.xlabel('time(sec)')
plt.xticks(rotation=45)
plt.ylabel('Q(C)')
plt.legend()
plt.show()

```


```python
#discharging

y0 = V*C
y11 = odeint(model,y0,t,args=(C,R1,0))
y12 = odeint(model,y0,t,args=(C,R2,0))
y13 = odeint(model,y0,t,args=(C,R3,0,))

# plot results
plt.plot(t,y11,'r-',linewidth=2,label='R1=100$\Omega$')
plt.plot(t,y12,'b--',linewidth=2,label='R2=200$\Omega$')
plt.plot(t,y13,'g:',linewidth=2,label='R3=300$\Omega$')
plt.xlabel('time(sec)')
plt.xticks(rotation=45)
plt.ylabel('Q(C)')
plt.legend()
plt.show()
```


```python

```

30d52066e1f08968e50f7785537a2236dc457c60
ipynb
Jupyter Notebook
ode1.ipynb
AmbaPant/NPS
0500f39f6708388d5c3f2b8d3e5ee5e56a1f646f
MIT
2020-09-16T03:21:55.000Z
2020-09-16T03:21:55.000Z
ode1.ipynb
AmbaPant/NPS
0500f39f6708388d5c3f2b8d3e5ee5e56a1f646f
MIT
ode1.ipynb
AmbaPant/NPS
0500f39f6708388d5c3f2b8d3e5ee5e56a1f646f
MIT
2020-08-10T12:17:21.000Z
2020-09-13T14:31:02.000Z
Qwen/Qwen-72B
1. YES
2. YES