Step 1 of 5 · Reading · ~3 min
Read
Math & Integration
Symplectic vs Explicit Euler
The previous lesson updated the velocity before the position and promised that this order matters. After this lesson your program will run both orders on the same spring and report how much energy each one has gained or lost, so you can see the difference instead of taking it on faith.
Two orders, one swap
Both methods use the same two ingredients, a position update p += v * dt and a velocity update v += a * dt. They differ only in the order:
explicit Euler symplectic (semi-implicit) Euler
a = force(p) / m a = force(p) / m
p = p + v * dt (old v) v = v + a * dt
v = v + a * dt p = p + v * dt (new v)
Both do exactly one force evaluation, both have the same cost, and both are first-order accurate. In explicit Euler the acceleration a comes from the position at the START of the step for both updates; moving the position first and then evaluating the force would be a different method.
Where the difference shows: a mass on a spring
A mass m on a spring of stiffness k has a = -(k/m) * x and a total energy that a real spring never changes:
E = 0.5 * m * v^2 + 0.5 * k * x^2
Trace with k = 1, m = 1, dt = 0.5, starting at x = 1, v = 0 (so E = 0.5):
explicit symplectic
step x v E x v E
0 1.000 0.000 0.500 1.000 0.000 0.500
1 1.000 -0.500 0.625 0.750 -0.500 0.406
2 0.750 -1.000 0.781 0.313 -0.875 0.432
Explicit Euler's energy climbs by the same factor every step (here 1.25). Symplectic Euler's energy wobbles slightly below and above the true value but does not run away.
Why: area in the (x, v) plane
Each step maps the state (x, v) to a new state by a fixed 2x2 matrix. Write w2 = k/m:
explicit: [ 1 dt ] determinant = 1 + w2 * dt^2 (greater than 1)
[ -w2*dt 1 ]
symplectic: [ 1 - w2*dt^2 dt ] determinant = 1
[ -w2*dt 1 ]
The determinant says how the step scales the area of a patch of states. Explicit Euler inflates it by 1 + w2*dt^2 every step, so after n steps the energy has been multiplied by (1 + w2*dt^2)^n. Halving dt only slows the growth, it never removes it. Symplectic Euler preserves area exactly, and that is the reason its energy stays in a bounded band. Real engines (Box2D, Bullet, Chipmunk) use it for that reason.
Limits of the stable method
Symplectic Euler is stable only while sqrt(k/m) * dt < 2. A stiff spring with a big step still explodes, so very stiff constraints need a smaller dt or a different method. For a constant force such as gravity both methods give the same velocity at every step; their positions differ by n * a * dt^2 after n steps, because explicit Euler always moves with the velocity from before the step.
Common mistakes
- Evaluating the spring force after moving the position in the explicit method. That quietly turns it into a different, better-behaved scheme and the energy ratio comes out wrong.
- Using the old velocity for the position in the symplectic method.
- Measuring the energy ratio against the energy after step one instead of the energy at the start.
- Dividing by zero when the body starts at rest at the equilibrium (
E0 = 0).
Your exercise
The starter reads the script and prints one line per method; you write the two integrators. Both start from the same state and are advanced by the same RUN commands. The most likely mistake is the evaluation order inside the explicit method.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…