An inductor (L) and a capacitor (C) wired in a loop form the simplest electrical oscillator. Energy continuously transfers between the capacitor's electric field and the inductor's magnetic field, producing a sinusoidal oscillation of charge and current — the electrical twin of a mass bouncing on a spring, and the resonant heart of every radio tuner.
L·q'' + R·q' + q/C = 0 → ideal: q'' + q/(LC) = 0
f = 1 / (2π√(LC)), E_C = q²/(2C), E_L = L·I²/2
The same q'' + q/(LC) = 0 equation describes a mass on a spring (m·x'' + k·x = 0). Inductance plays the role of mass, 1/C the role of spring stiffness, charge the role of position, and current the role of velocity. Discovering this mechanical–electrical analogy let engineers reuse a century of mechanics maths for electronics.
An LC oscillator is a circuit made of an inductor (L) and a capacitor (C) connected in a loop. Energy sloshes back and forth between the capacitor's electric field and the inductor's magnetic field, producing a sinusoidal oscillation of charge and current.
The resonant frequency is f = 1/(2π√LC). Larger inductance or capacitance lowers the frequency; smaller values raise it. This is why tuning a radio adjusts a variable capacitor to change which station's frequency the LC circuit resonates with.
Charge q behaves like position, current I like velocity, inductance L like mass, and 1/C like the spring constant. Capacitor energy q²/2C mirrors spring potential energy, while inductor energy LI²/2 mirrors kinetic energy. Both systems obey the same harmonic equation.
In an ideal LC circuit, total energy is conserved and merely transfers between the capacitor and the inductor twice per cycle. When the capacitor is fully charged, all energy is electric; a quarter-cycle later the current peaks and all energy is magnetic in the coil.
Real circuits have resistance, which dissipates energy as heat. This causes damped oscillations whose amplitude decays exponentially. With enough resistance the circuit becomes overdamped and stops oscillating altogether, returning monotonically to equilibrium.
Applying Kirchhoff's voltage law gives L·q'' + R·q' + q/C = 0. Without resistance this reduces to q'' + q/(LC) = 0, the simple harmonic oscillator equation with angular frequency ω = 1/√(LC).
The quality factor Q = (1/R)√(L/C) measures how many oscillations occur before the energy decays significantly. High-Q circuits ring for a long time and are highly selective in frequency — essential for sharp radio tuning.
Only the idealised lossless circuit oscillates forever. Any real inductor and capacitor have resistance, so practical oscillators need an active element (like a transistor amplifier) to inject energy each cycle and sustain a constant amplitude.
An LC loop is nicknamed a tank circuit because it stores and exchanges energy like a reservoir, holding oscillating energy that 'sloshes' between the two components much as liquid sloshes in a tank.
LC oscillators set the operating frequency of radios, TVs, and wireless transmitters, form bandpass filters, generate clock signals, and serve as the resonant element in metal detectors, induction heaters, and wireless charging.
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.
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.
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.
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.
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.
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.
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.
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.
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.