RK4
✓ Published0🌍 Public
Aabernier
Last edited Aug 12, 2012
Created on Aug 12, 2012
This example demonstrates the numerical integration of a damped harmonic oscillator using the fourth-order Runge-Kutta method. It shows how the system’s position and velocity evolve over time, starting from an initial displacement of 100 and decaying toward zero. The code implements the RK4 algorithm step by step, evaluating acceleration from a spring constant and damping coefficient, then updating the state iteratively. Results are printed to the console via `console.log`, and the loop continues until both position and velocity fall below a small threshold. No external libraries are used; the example relies entirely on plain JavaScript functions.
AI-generated description