FREE LESSON · Graphics & simulation · 5 OF 5

Numerical integration and simulation stability

Numerical integration and simulation stability: Explain how a correct force law can still produce an unstable animation.

Prerequisites: Derivatives, vectors, and floating-point arithmetic.

Learning objectives

  • Step a motion model numerically.
  • Distinguish discretization error from model error.
  • Test convergence and conservation.

Simulation approximates a changing state

A mechanical model can describe position x, velocity v, and acceleration a. Differential equations specify how those quantities change continuously. A program advances them in finite time steps. The integration method and step size introduce numerical behavior beyond the physical model itself.

Explicit Euler uses x_next=x+h v and v_next=v+h a(x,v,t). Both right-hand sides use the old state. For constant acceleration, the velocity update is exact over one step, but the position update omits the half-acceleration term. Smaller steps generally reduce this local approximation error, though roundoff and computational cost also matter.

Work a falling particle

Use upward-positive coordinates, x=10, v=0, acceleration -10, and h=0.1. Explicit Euler gives x_next=10 and v_next=-1. The exact constant-acceleration position after that step is 9.95. Semi-implicit Euler updates velocity first and uses the new velocity for position, giving x_next=9.9. Neither one-step position is exact, though their long-term behavior can differ substantially.

For a spring with acceleration proportional to negative displacement, explicit Euler can add energy and produce growing oscillations even when the continuous system conserves energy. Stability depends on the method, step size, and system dynamics. A visually smooth first few frames do not establish a stable simulation.

Constraints and collisions change the problem

Detecting a collision only at the end of a large step can miss a thin obstacle entirely. Smaller steps, swept tests, or continuous collision methods address different forms of this problem. After contact, the response must specify restitution, friction, and constraints. Simply reversing velocity after deep penetration can create energy or jitter.

Units are part of correctness. Mixing milliseconds with seconds or centimeters with meters changes forces and motion by large factors. Keep units explicit in formulas and test fixtures. Randomized simulations also need controlled seeds when reproducing a failure.

Verify a numerical method

Use a problem with a known solution, such as constant acceleration, and compare error at the same final time while halving h. Check qualitative invariants where the model supports them: bounded energy, nonpenetration, or conservation of momentum. Distinguish numerical error from an intentionally simplified physical model.

A convergence test is evidence about the implementation and regime tested, not a proof for every stiff or chaotic system. Document the method, step size, tolerances, and known limits. Simulation quality comes from controlling these assumptions and errors, not from making the animation look convincing.

Practice problem

From x=5, v=2, a=-4, use h=0.5 for one explicit Euler step, one semi-implicit Euler step, and the exact constant-acceleration solution. Explain a convergence experiment that compares methods fairly.

Worked solution

Explicit Euler gives x=5+0.5×2=6 and v=2+0.5×(-4)=0. Semi-implicit Euler uses the new velocity and gives x=5. The exact position is 5+2×0.5+0.5×(-4)×0.5²=5.5, with velocity zero. To compare convergence, integrate each method to the same final time using h, h/2, and h/4, then measure position and velocity errors against the known solution. Keep the physical model and initial conditions fixed. Comparing different final times or only visual smoothness would confound the result.

Check your understanding

Explicit Euler evaluates its right-hand sides using which state?

  • The exact future state.
  • The old state.
  • An arbitrary random state.
  • Only the final frame.
Explanation

The method advances using derivatives evaluated at the current state.

What does a smaller time step guarantee for every simulation?

  • Perfect energy conservation.
  • No collision can be missed.
  • No universal guarantee; stability and error depend on the method and system.
  • An exact solution.
Explanation

Step size matters, but model stiffness, method choice, and event handling also matter.

Primary reading

Open the study and save your work →