DEV Community

Surendra Singh Kamboj
Surendra Singh Kamboj

Posted on AI-assisted

LC oscillations in JavaScript: frequency, peak current and the energy swap

An ideal LC circuit oscillates at omega = 1 / sqrt(L C), and the total energy Q0^2 / (2C) keeps moving between the capacitor and the inductor. Numbers below were run in Node.

How do you find the frequency and peak current?

const L = 10e-3, C = 100e-6;                 // 10 mH, 100 microfarad
const w = 1 / Math.sqrt(L * C);              // rad/s
console.log(w.toFixed(1), (w / (2 * Math.PI)).toFixed(2), (2 * Math.PI / w * 1e3).toFixed(3));
// 1000.0 rad/s, 159.15 Hz, 6.283 ms
const Q0 = 1e-3;                             // initial charge, C
const Imax = Q0 * w;
console.log(Imax.toFixed(3));                              // 1.000 A
console.log((Q0 * Q0 / (2 * C)).toFixed(4), (0.5 * L * Imax ** 2).toFixed(4)); // 0.0050 J each
Enter fullscreen mode Exit fullscreen mode
Quantity Value
Angular frequency 1000 rad/s
Frequency 159.15 Hz
Period 6.283 ms
Peak current 1.000 A
Energy 5.0 mJ, all in C at the start, all in L a quarter period later

Why is the energy the same in both forms?

Because no resistance dissipates it: the maximum electric energy Q0^2/(2C) equals the maximum magnetic energy L Imax^2/2, which the last two numbers above confirm.

FAQ: What happens if the capacitance is multiplied by 4?

The frequency is halved, because omega goes as 1 over the square root of C.

I build PractiSci, a free-to-start virtual lab. See the swap animated: LC oscillations lab. Chapter guide: Electromagnetic induction.

Top comments (0)