A Byte of PhysicsLogo

Numerical stability in trajectory simulation

A simulation can look smooth while its numbers drift away from the model. An ideal oscillator gives a useful test because its total energy should stay constant.

Think like a programmer

An integrator is a replaceable implementation of the local update contract. Conservation laws are regression tests: if energy changes in a closed model, measure the numerical method before inventing new physics.

Model checklist

Inputs
Initial position, velocity, time step, and integrator.
State
Oscillator position and velocity.
Rule
Advance the differential equation one fixed step.
Output
State after twenty seconds and total energy.
Check
Exact total energy remains 0.5 in these normalized units.
\[E=\\frac{1}{2}(x^2+v^2)\]

Integrator energy drift

Run the same ideal oscillator with Euler and fourth-order Runge–Kutta steps, then compare an energy invariant.

Euler state
x = 4.473, v = -5.522
RK4 state
x = 0.408, v = -0.913

Euler energy 25.2525; RK4 energy 0.5000; exact energy 0.5000.

Try this experiment

Prediction: A smaller time step reduces error, and RK4 generally drifts less than Euler at the same step.

Compare 0.50 s and 0.02 s steps. Use the energy values rather than the display alone to decide which run is more reliable.

Where this model breaks

Energy conservation is not the right test for driven, damped, or open systems. A stable numerical method also cannot rescue an incorrect force model or invalid initial data.

Summary

Choose an integrator deliberately. Track a physical invariant, state the time step, and compare methods against a known model before trusting a trajectory.

Glossary

Self-check

  1. What invariant tests this oscillator?
  2. Why does a smaller step help?
  3. When is energy conservation not expected?

Sources

Model contract

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})\]
Inputs
Quantities you set or measure, with units and useful bounds.
State
Values the program must retain to reproduce the next result.
Rule
The relationship or update that turns inputs and state into a result.
Check
A known limit, unit check, invariant, or measured result that can expose a bad model.

Implement the idea as a model

For Numerical Stability in Trajectory Simulation, write down the quantities you can control, the values your program must retain, and the result a reader could inspect. In Motion in 2D and 3D, the useful program is not the drawing: it is the smallest explicit model that makes a prediction you can test.

Guided experiment

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.

Where this model breaks

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.

Summary

Treat Numerical Stability in Trajectory Simulation 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.

Glossary

  • Input: a measured value or chosen parameter supplied to a model.
  • State: the smallest set of values needed to continue or reproduce a model.
  • Validation: comparing an output with a known result, limit, invariant, or measurement.

Self-check

  1. Which values are inputs, and which values must remain state?
  2. What observable result would tell you the model is behaving as expected?
  3. Which assumption would you test first before applying the model to a real system?

Model review: turn Numerical Stability in Trajectory Simulation into a test

Compare Euler and Runge–Kutta time steps on an ideal oscillator and use energy drift as an error signal.

  1. Name the inputs and units that the motion in 2d and 3d model needs.
  2. Separate the state you must keep from values you can calculate when needed.
  3. Write one rule that maps the current state and inputs to an observable result.
  4. Choose a limiting case, unit check, invariant, or known result before trusting an output.
  5. State one assumption you would change before using this simplified model for a real decision.

Share to: