How to compute capacitor charging energy in Python using UliEngineering
You can easily compute the energy stored in a charged capacitor using the UliEngineering Python library:
from UliEngineering.Electronics.Capacitors import capacitor_charging_energy
from UliEngineering.EngineerIO import *
# Compute energy for 100µF at 5V
energy = capacitor_charging_energy("100uF", "5V")
print(f"Energy (100µF, 5V): {format_value(energy, 'J')}")
# Compute energy for 1nF at 12V
energy = capacitor_charging_energy("1nF", "12V")
print(f"Energy (1nF, 12V): {format_value(energy, 'J')}")Example output
Energy (100µF, 5V): 1.25 mJ
Energy (1nF, 12V): 72.0 nJThe capacitor charging energy represents the amount of electrical energy stored in the capacitor’s electric field when charged to a specific voltage. This energy is proportional to the capacitance and the square of the voltage. Understanding capacitor energy is essential for power supply design, energy harvesting systems, and calculating the potential energy available for discharge in timing or pulse circuits.
The energy is computed using the formula: $E = \frac{1}{2} C V^2$, where $E$ is the energy in joules, $C$ is the capacitance in farads, and $V$ is the voltage in volts. The factor of 1/2 arises because the voltage increases linearly from 0 to V during charging, so the average voltage during the charging process is V/2.
The plot above shows capacitor charging energy versus voltage for different capacitance values. Notice the quadratic relationship: energy increases with the square of the voltage, so doubling the voltage quadruples the stored energy. This demonstrates why higher voltage capacitors can store significantly more energy for a given capacitance.
Related posts
- How to compute capacitor charge in Python using UliEngineering
- How to compute capacitor voltage by energy in Python using UliEngineering
- How to compute capacitor capacitance by energy in Python using UliEngineering
Plot generation script
#!/usr/bin/env python3
import matplotlib.pyplot as plt
import numpy as np
import sys
sys.path.insert(0, '/home/uli/dev/UliEngineering')
from UliEngineering.Electronics.Capacitors import capacitor_charging_energy
# Voltage range for plotting
V = np.linspace(0, 25, 100) # 0 to 25V
# Create plot
plt.figure(figsize=(10, 6))
# Calculate energy for different capacitances
capacitances = [
(1e-6, '1 µF', 'blue'),
(10e-6, '10 µF', 'green'),
(100e-6, '100 µF', 'red'),
(1e-3, '1 mF', 'purple'),
]
for C, label, color in capacitances:
E = 0.5 * C * V ** 2
plt.plot(V, E * 1000, label=label, color=color, linewidth=2)
plt.xlabel('Voltage (V)', fontsize=12)
plt.ylabel('Energy (mJ)', fontsize=12)
plt.title('Capacitor Charging Energy vs Voltage', fontsize=14, fontweight='bold')
plt.legend(loc='upper left', fontsize=10)
plt.grid(True, alpha=0.3)
plt.tight_layout()
plt.savefig('capacitor_charging_energy_plot.svg', format='svg', dpi=300)