Home > Python > Ordinary Differential Equation-1

Ch. 6.3 Capacitor Charging / Discharging

Chapters Index
Program 1

Capacitor Charging / Discharging

Python 3.11 Ready

                                
Click "Run Code" to execute script and render figures.

Mathematical Problem Formulation

ODE for Capacitor Charging and Discharging

The voltage across a capacitor V(t) in an RC circuit can be described by the following ODE:

Charging:
dV(t)/dt = (1/RC) * (Vin - V(t))

Discharging:
dV(t)/dt = -V(t)/(RC)

Here:

  • V(t) is the voltage across the capacitor at time t.
  • Vin is the input voltage (for charging).
  • R is the resistance in ohms.
  • C is the capacitance in farads.
Theoretical Principles & Computational Physics Guide

RC Circuit Transients: Capacitor Charging & Discharging Dynamics

Dr. Alorika Chatterjee & Dr. Anirban Shaw Science & Physics Learners Python 3 / NumPy / SciPy

1. Core Principles & Theoretical Framework

First-Order Relaxation: Governs exponential charge and voltage transients in resistive-capacitive networks.
Characteristic Time Constant: Relaxation timescale $\tau = RC$ determines the rate of charging and discharging.
Asymptotic Saturation: Charging capacitor reaches $\approx 63.2\%$ of EMF at $t = \tau$, and $> 99\%$ at $t = 5\tau$.

2. Mathematical Formulation & Algorithmic Pipeline

Kirchhoff's voltage law governing an RC series loop:

$$ R \frac{dq}{dt} + \frac{q}{C} = \mathcal{E} \implies R C \frac{dV_C}{dt} + V_C = \mathcal{E}, \quad V_C(t) = \mathcal{E}\left(1 - e^{-t/\tau}\right) $$

3. Numerical Mechanics & Implementation Logic

  • Time Discretization: Choose step size $h \ll RC$ (e.g. $h = 0.01 RC$) to ensure numerical stability.
  • Transient Update: Advance voltage $V_{n+1} = V_n + \frac{h}{RC}(\mathcal{E} - V_n)$.
  • Phase Switching: At specified discharge time $t_{\text{switch}}$, set driving EMF $\mathcal{E} = 0$ to observe decay.

4. Relevant Computational Practice Exercises

Exercise 1
Simulate capacitor charging from $t = 0$ to $5\tau$ and verify that $V_C(\tau) \approx 0.632\mathcal{E}$.
Exercise 2
Simulate an RC circuit driven by a square-wave source and plot voltage response demonstrating low-pass filtering.
Exercise 3
Compute instantaneous power $P(t) = I(t)^2 R$ and verify total energy conservation during complete charge-discharge cycles.
Standard Literature & References:
  • David J. Griffiths, "Introduction to Electrodynamics", Cambridge University Press (2017).