An ideal mass-spring oscillator is an ordinary differential equation: acceleration is proportional to negative displacement. Its state is position and velocity, not an already-drawn sine wave. The sinusoid is a reference solution for a stated ideal regime, useful for validating an integrator rather than replacing the state update.
{ position, velocity } at named times with a declared method. Keep the analytic frequency/phase reference, numerical state trace, total-energy ledger, and error/refinement table separate. Never derive force from the rendered spring length or replace state with a precomputed sine value once the model gains a drive or nonlinearity.Change stiffness, damping, and displacement. The force is restoring; damping affects velocity once the system is moving.
Stiffness 20 N/m; damping 1; displacement 0.40 m; acceleration -8.00 m/s²; natural angular frequency 4.47 rad/s; energy 1.60 J.
For an ideal solution, initial position and velocity choose amplitude and phase while m and k choose the natural angular frequency. This separates state from configuration: changing stiffness changes derived acceleration and frequency immediately, but position changes only through an update over time.
Use at least three fixtures: release from positive displacement, pass equilibrium with nonzero velocity, and zero stiffness. Compare numerical x and v with the analytic solution at shared physical times. A method can have a plausible period while drifting in energy, or conserve energy reasonably while shifting phase; record both errors. The correct invariant depends on boundary and force model, so do not demand conservation after adding damping or drive without their transfer ledger.
Prediction: Increasing stiffness raises the natural frequency, while changing initial displacement changes amplitude but not the ideal frequency.
Run release and equilibrium-crossing fixtures. Change k at fixed m, then change x0 at fixed k/m. Record calculated ω0, numerical period, phase error, and total energy at shared times for two step sizes. Add damping only after the undamped reference passes, and explain which energy transfer makes the closed invariant inapplicable.Implement oscillation as a second-order state update. Use the ideal frequency, analytic trace, and energy ledger as separate reference checks, then record integrator/refinement behavior before adding damping, drive, or nonlinear force laws.
Treat the lesson as a small function before treating it as a fact to memorize. Give every value a unit, keep only the state needed for the next step, and make the output easy to inspect.
\[\text{observable output} = f(\text{inputs},\,\text{state})\]For Simple Harmonic Motion as ODE, write down the quantities you can control, the values your program must retain, and the result a reader could inspect. In Oscillations, the useful program is not the drawing: it is the smallest explicit model that makes a prediction you can test.
Prediction: changing one declared input while holding the others fixed should change only the outputs that the model connects to that input. Choose one input, predict the direction of change, then check a limiting case such as zero, a symmetric arrangement, or a familiar low-speed or small-change approximation.
This lesson is a teaching model, not a complete simulator. Before using it outside the stated question, check which interactions, scales, uncertainties, boundary conditions, and measurement limits it leaves out.
Treat Simple Harmonic Motion as ODE as a contract: named inputs and units enter a rule, the rule produces an observable result, and a known limit or invariant checks whether the implementation deserves trust.
Implement an ideal mass-spring oscillator from position, velocity, and a restoring acceleration function.