Part 1: The Failure of Naive Integration
ODE Methods & Conservation | Numerical Methods Module 3 | ASTR 596
Learning Outcomes¶
By the end of this section, you will be able to:
Implement Euler’s method and witness its catastrophic energy drift
Analyze local vs global error accumulation through Taylor series
Understand why higher accuracy doesn’t guarantee better long-term behavior
Recognize the geometric failure modes in phase space
Predict when and how integration methods will fail
From Continuous to Discrete¶
The fundamental ODE initial value problem asks us to find a function given its rate of change:
This has the formal integral solution:
But this Initial Value Problem contains a circular dependency: to find , we need to integrate , but depends on the unknown solution itself!
Numerical methods break this circular dependency by making assumptions about how behaves over small time intervals:
Constant derivative assumption (Euler): Assume stays constant over
Linear variation assumption (Trapezoidal): Assume varies linearly between endpoints
Polynomial approximation (Runge-Kutta): Assume follows a polynomial of degree
Each assumption leads to a different family of methods with different error behaviors, stability properties, and conservation characteristics.
The Dimensional Analysis of Timesteps¶
Before diving into specific methods, let’s understand what constrains our choice of timestep from pure dimensional analysis.
For any oscillatory system with characteristic frequency :
Nyquist requirement: (must sample twice per oscillation)
Accuracy requirement: (need ~60 points per period)
Typical choice: (600 points per period)
For gravitational N-body systems, multiple timescales compete:
Orbital period: (for semi-major axis a)
Close encounter: (where v_rel is relative velocity)
Shortest scale:
Required timestep:
Example - Earth-Sun system:
Period:
Typical timestep: s
High accuracy: s
Euler’s Method - The Simplest Approach¶
Mathematical Formulation¶
Euler’s method is the most straightforward discretization possible. Given the ODE
at time with solution , and a timestep , we approximate:
This assumes the derivative remains constant over the entire interval — essentially extending the tangent line at forward by distance .

Figure 1:Euler’s method extends the tangent line at each point, accumulating error by ignoring the solution’s curvature. The diagram shows how Euler follows straight line segments (red) that deviate increasingly from the true curved solution (blue). The local truncation error at each step is proportional to , but these errors accumulate to give global error.
Taylor Series Analysis of Error¶
To understand Euler’s error precisely, we need the Taylor series. The true solution at is:
Since by definition of our ODE, Euler’s method gives:
The local truncation error — the error in one step — is:
The leading error term is , making Euler locally second-order accurate. But errors accumulate! Over steps to reach final time , the global error becomes:
Euler is globally first-order: halving the timestep only halves the total error.
The Energy Drift Catastrophe¶
Let’s see Euler fail catastrophically on the harmonic oscillator:
Converting to first-order system:
The true solution has constant energy
Implementation and Analysis¶
import numpy as np
def euler_harmonic(x0, v0, omega, h, n_steps):
"""Integrate harmonic oscillator with Euler's method"""
x, v = x0, v0
E0 = 0.5 * (v0**2 + omega**2 * x0**2)
energies = [E0]
for i in range(n_steps):
# Euler update
a = -omega**2 * x
x = x + h * v
v = v + h * a
# Energy (should be constant, but...)
E = 0.5 * (v**2 + omega**2 * x**2)
energies.append(E)
return energiesThe shocking result: energy grows approximately linearly with time! After 1000 orbital periods, energy has typically increased by 10%. The orbit spirals outward, violating conservation of energy.
Mathematical Analysis of Energy Growth¶
For the harmonic oscillator with Euler’s method, we can derive the exact energy growth rate. Starting with position and velocity :
The energy after one step:
Substituting the updates:
Expanding:
Therefore:
The amplification factor means energy grows exponentially! After steps:
For Earth’s orbit with day and years:
A 10% energy increase means that Earth would drift into a higher orbit!

Figure 2:Euler’s method systematically violates energy conservation with catastrophic consequences. The figure shows a harmonic oscillator integrated over 10 periods with timestep h = 0.02: (Top left) Phase space trajectory spirals outward as energy increases ~3.5×. (Top right) Energy grows monotonically from amplification factor (1 + h²ω²) ≈ 1.0004 per step compounding over many orbits. (Bottom left) Spatial orbit expands continuously—a planet would spiral away from its star! (Bottom right) Error analysis shows systematic energy injection (red line) versus oscillating position errors (teal). This demonstrates why Euler fails for long-term dynamics despite being locally accurate.
Why Euler Fails: The Geometric View¶
In phase space (position-velocity space), the harmonic oscillator traces a circle. Each Euler step moves along the tangent to the circle, placing the new point slightly outside. The phase space area increases, violating Liouville’s theorem that phase space volume must be preserved in Hamiltonian systems.
The Phase Error Problem¶
Even if we could tolerate energy drift, Euler has another fatal flaw: phase error. The frequency of oscillation is wrong:
After oscillations, the phase error is:
This means that even with small timesteps, the phase error accumulates linearly with time.
When Does Euler Work?¶
Despite these failures, Euler has legitimate uses:
Very short integrations where
Highly dissipative systems where energy should decay
Quick explorations before using better methods
Teaching why better methods are needed!
The Fundamental Lesson¶
Euler’s method reveals a profound truth about numerical integration:
Local accuracy does not guarantee global stability
Euler is locally second-order accurate ( per step), yet it systematically violates conservation laws. This isn’t a bug — it’s a fundamental property of the discretization.
The tangent line approximation, while locally accurate, doesn’t respect the curved geometry of phase space. Each step compounds this geometric error until the qualitative behavior is wrong.
Bridge to Part 2: The Quest for Better Methods¶
Euler’s catastrophic failure motivates our search for better integration methods. The failure isn’t just about accuracy — it’s about systematic bias. Every Euler step pushes slightly outward from the true trajectory. This accumulation of geometric errors destroys the physics we’re trying to simulate.
What we need are methods that:
Sample the derivative at multiple points to cancel biases
Achieve higher-order accuracy to reduce error accumulation
Maintain stability over long integration times
Preserve conservation laws or at least bound their violation
In Part 2, we’ll explore the Runge-Kutta family — methods that evaluate the derivative at carefully chosen intermediate points to achieve higher accuracy. By sampling the “curvature” of the solution, these methods can follow the true trajectory more faithfully. But as we’ll discover, even fourth-order accuracy isn’t enough to preserve energy over cosmic timescales.
The journey from Euler to modern integration methods is a journey from naive approximation to deep understanding of geometric structure. Each method we develop addresses specific failures of its predecessors, leading ultimately to symplectic integrators that preserve the fundamental geometry of physics.
Next: Part 2 - Building Better Methods