HomeElectronics & CircuitsLC Oscillator — Energy Sloshing Between L and C

🔌 LC Oscillator — Energy Sloshing Between L and C

An inductor and capacitor exchange energy back and forth, oscillating at f=1/(2π√LC) — the electrical analogue of a mass on a spring, the heart of every radio tuner.

Electronics & Circuits3DEasy60 FPS
lc-oscillator ↗ Open standalone

About this simulation

This simulation numerically integrates the series LC circuit equation L·q'' + R·q' + q/C = 0, where q is the charge (coulombs, C) on the capacitor and q' = I is the current. Every animation frame advances the state with 8 sub-steps of the fourth-order Runge–Kutta (RK4) method for numerical stability. With resistance R = 0 the equation reduces to the ideal case q'' + q/(LC) = 0, a simple harmonic oscillator identical in form to a mass on a spring, oscillating at angular frequency ω = 1/√(LC). Raising R adds a drag term that bleeds energy away as heat, so the swings of charge and current decay exponentially instead of repeating forever.

🔬 What it shows

An animated capacitor (charge shown as a glowing +/- polarity on its plates), an inductor coil whose magnetic-field glow scales with current, moving dots around the wire loop that reveal current direction and speed, two energy bars for E_C = q²/(2C) and E_L = L·I²/2 trading height as energy sloshes between them, a live q(t)/I(t) waveform strip, and a small mass-on-spring drawing whose displacement mirrors the charge in real time.

🎮 How to use it

Drag the sliders for Inductance L (0.2-4 H), Capacitance C (0.2-4 F), initial charge q₀ (0.1-1.5), and Resistance R (0-2 Ω); any change resets the run to q=q₀, I=0. Pause/Play toggles the RK4 integration, Reset restarts from the current slider values, and the ? button opens a popup with the full equations and controls.

💡 Did you know?

The same q'' + q/(LC) = 0 equation is why old radios were "tuned" by turning a knob: the knob rotated a variable capacitor, changing C so that f = 1/(2π√(LC)) matched the carrier frequency of the desired broadcast station, making the LC tank resonate with it while rejecting the rest.

Frequently asked questions

How does the simulation actually solve the LC circuit equation?

It applies fourth-order Runge-Kutta (RK4) integration to the pair of first-order equations q' = I and I' = -(R·I + q/C)/L, taking 8 smaller sub-steps every animation frame so the update stays numerically stable even at the extreme ends of the L, C, and R sliders.

Why does turning up the Resistance slider make the oscillation die out?

R models real wire and coil losses that convert electrical energy into heat. In the RK4 update, the current's rate of change includes a term -R·I/L that opposes the motion, so each swing of charge and current loses a little energy; push R high enough and the circuit becomes overdamped, decaying to zero instead of ringing.

What do the moving dots on the rectangular wire represent?

They visualise conventional current flowing around the loop. Their direction flips with the sign of the current I, and their speed is drawn proportional to |I| relative to the slider-dependent scale maxI = q₀/√(LC), so a faster stream of dots means a larger instantaneous current.

Why is there a mass-on-spring drawing next to the circuit?

It illustrates the exact analogy behind the code: the charge q is mapped directly onto the spring's displacement, because both obey the same differential equation (m·x'' + k·x = 0 versus L·q'' + q/C = 0). Watching the spring stretch and compress in step with the capacitor's charge shows that the electrical and mechanical oscillators are solving identical maths.

What happens to the two energy bars (E_C and E_L) as the circuit oscillates?

They show the instantaneous split of stored energy between the capacitor's electric field, E_C = q²/(2C), and the inductor's magnetic field, E_L = L·I²/2. As the simulation runs the bars trade height: E_C peaks when the capacitor is fully charged and current is zero, E_L peaks a quarter-cycle later when current is maximum and charge is zero, and in the lossless case (R=0) their sum stays constant.

⚙ Under the hood

An inductor and capacitor exchange energy back and forth, oscillating at f=1/(2π√LC) — the electrical analogue of a mass on a spring, the heart of every radio tuner.

LC circuitoscillationenergy exchangeresonanceCanvas 2Dcurrent

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)