Section 6.4: Numerical integration and stability

A Careful Control Loop
Technical illustration for Section 6.4: Numerical integration and stability.
Figure 6.4A: Euler, Runge-Kutta, and semi-implicit integration compared on a spring-mass trajectory: explicit Euler spirals outward (unstable), while the semi-implicit method stays bounded with the same step size.
Big Picture

Numerical integration and stability is one lens on dynamics and simulation math. We study it because an embodied agent needs decisions that survive contact with noisy sensors, delayed effects, and changing environments.

This section develops the technical contract for Numerical integration and stability into a usable mental model. First we define the object of study, then we connect it to the agent loop, then we test it with a compact implementation.

The key question in Numerical integration and stability is practical: what must the agent know, what can it observe, what action is available, and what evidence shows that the action worked under the stated conditions?

Action Is The Test

A representation earns its place when it changes the measurable action interface. In Numerical integration and stability, the reader should keep asking which decision becomes easier, safer, or more reliable.

Theory

For Numerical integration and stability, the practical design rule is to make the interface inspectable before optimization begins: inputs, outputs, units, latency, bounds, and failure labels should all be visible in the saved artifact.

Mechanism

The mechanism in Numerical integration and stability is the contract between representation and action. Name what enters the module, what leaves it, which assumptions make that transformation valid, and which log would reveal a bad handoff.

Worked Example: Euler vs RK4 vs Symplectic Euler on a Pendulum

The cleanest stress test for an integrator is an undamped pendulum, because its true total energy is conserved exactly. Any energy the integrator gains or loses is pure numerical artifact. The pendulum equation of motion comes from the Lagrangian $L = T - V$ with $T = \tfrac{1}{2}m\ell^2\dot{\theta}^2$ and $V = -mg\ell\cos\theta$. Applying the Euler-Lagrange equation $\tfrac{d}{dt}\tfrac{\partial L}{\partial\dot{\theta}} - \tfrac{\partial L}{\partial\theta} = 0$ gives $\ddot{\theta} = -\tfrac{g}{\ell}\sin\theta$.

Three integrators handle the same dynamics very differently:

import numpy as np

g, L = 9.81, 1.0
def accel(theta):
    return -(g / L) * np.sin(theta)

def energy(theta, omega):
    return 0.5 * L**2 * omega**2 + g * L * (1 - np.cos(theta))

def integrate(method, theta0, omega0, dt, steps):
    theta, omega = theta0, omega0
    E = [energy(theta, omega)]
    for _ in range(steps):
        if method == "euler":                 # explicit Euler
            theta_new = theta + dt * omega
            omega_new = omega + dt * accel(theta)
            theta, omega = theta_new, omega_new
        elif method == "symplectic":          # semi-implicit Euler
            omega = omega + dt * accel(theta)
            theta = theta + dt * omega
        elif method == "rk4":
            def f(s):
                th, om = s
                return np.array([om, accel(th)])
            s = np.array([theta, omega])
            k1 = f(s)
            k2 = f(s + 0.5 * dt * k1)
            k3 = f(s + 0.5 * dt * k2)
            k4 = f(s + dt * k3)
            s = s + (dt / 6.0) * (k1 + 2*k2 + 2*k3 + k4)
            theta, omega = s
        E.append(energy(theta, omega))
    return np.array(E)

theta0, omega0 = 0.5, 0.0       # release from 0.5 rad at rest
dt, steps = 0.05, 4000          # 200 s of simulated time
E0 = energy(theta0, omega0)

for method in ["euler", "symplectic", "rk4"]:
    E = integrate(method, theta0, omega0, dt, steps)
    drift = (E[-1] - E0) / E0 * 100
    print(f"{method:<11} energy drift over 200 s: {drift:+8.2f}%   "
          f"(min={E.min():.4f}, max={E.max():.4f})")

The printed drift makes the contrast concrete: explicit Euler gains a large positive percentage (the pendulum swings ever higher, which is physically impossible), symplectic Euler keeps the energy oscillating within a small bounded band around $E_0$, and RK4 holds energy to within a tiny fraction of a percent. The lesson for embodied AI: choose the integrator for the property the task needs. Use symplectic methods for long-horizon stability in a learning loop, and a high-order method like RK4 when short-horizon trajectory accuracy matters more than energy bookkeeping. Always log $\Delta t$ and the integrator, because the policy learns the discrete system you actually simulate, not the continuous one you intended.

Library Shortcut

For Numerical integration and stability, the hand-built fragment exposes the physical assumption before maintained tools take over. MuJoCo, MJX, Drake, Pinocchio, and Isaac Lab are useful only when the same mass, contact, actuator, and timestep contract is preserved.

Practical Recipe

  1. Write the observation, action, and success metric before choosing a model.
  2. Build a baseline that is simple enough to debug by inspection.
  3. Add the library implementation only after the baseline behavior is understood.
  4. Record failures as structured cases: perception error, state error, planning error, control error, or evaluation error.
  5. Run at least one perturbation test before trusting the result.
Common Failure Mode

The common mistake in Numerical integration and stability is to celebrate the component score before checking the closed-loop handoff. The failure usually appears at the boundary: stale state, wrong frame, delayed action, saturated actuator, or metric that ignores the real task cost.

Practical Example

A robotics team using Numerical integration and stability should log not only final success, but intermediate observations, chosen actions, controller status, and recovery events. The logs reveal whether the method is solving the task or merely passing the easiest episodes.

Memory Hook

Treat numerical integration and stability like a control-room label. If the label does not tell a future debugger what moved, what sensed, or what failed, it is decoration rather than engineering knowledge.

Research Frontier

For Numerical integration and stability, treat frontier claims as hypotheses until they expose enough detail to reproduce the result: data boundary, embodiment, controller interface, evaluation panel, and failure cases.

Self Check

Can you name the observation, state estimate, action, success metric, and most likely failure mode for Numerical integration and stability? If not, the system boundary is still too vague.

Production Pattern

Numerical integration and stability sits inside the Part II robotics contract: geometry defines where things are, kinematics defines what motion is possible, dynamics defines what motion costs, control defines how errors are corrected, and sensing defines what the agent can know on time.

Tie numerical integration choices to stability, energy behavior, timestep, and controller update rate. This makes the section useful to students, builders, and researchers at the same time: the idea has an intuitive role, a formal interface, a runnable check, and a failure mode that can be reproduced.

An integrator is the contract that turns continuous dynamics into a sequence of states. The danger is that the sequence can be numerically stable even when it is physically wrong, or physically plausible for one timestep and unstable for another. For robot learning, that means a policy can learn simulator artifacts such as extra damping, energy gain, or contact jitter.

Timestep Is A Model Parameter

Do not treat $\Delta t$ as a rendering detail. It changes the discrete system the policy experiences, the stiffness the solver can tolerate, and the delay between control updates. A simulator result without timestep and integrator settings is not reproducible evidence.

Mechanism To Watch

For Numerical integration and stability, dynamics adds causes of motion: forces, torques, inertia, contact impulses, and integration. Keep units, solver step, contact parameters, and energy behavior visible.

Library Choices And Verification Checks
Tool or LibraryWhat It HandlesVerification Check
MuJoCoruns articulated dynamics and contact simulation for robot learning experimentsVerify timestep, solver parameters, contact settings, and reset semantics.
MJXruns articulated dynamics and contact simulation for robot learning experimentsVerify timestep, solver parameters, contact settings, and reset semantics.
Drakemodels dynamical systems, multibody plants, optimization, and controllersVerify scalar type, plant finalization, frame convention, and solver status.
Pinocchiocomputes articulated-body kinematics, dynamics, and derivativesVerify model frames, joint ordering, and derivative convention against the URDF.
Isaac Labscales robot-learning simulation with GPU workflows and sensor-rich scenesVerify environment parity, reset distribution, and logged seeds before training.

Use this recipe when turning Numerical integration and stability into code, a simulator experiment, or a robot diagnostic. The point is not to use every library. The point is to keep the hand-built baseline and the maintained-tool path comparable.

  1. Specify mass, inertia, actuator limits, contact model, timestep, and solver tolerance before running a rollout.
  2. Run one free-motion test and one contact test with logged energy, constraint violation, and penetration depth.
  3. Compare the hand calculation with MuJoCo, Drake, Pinocchio, or MJX on the same model and timestep.
  4. Store solver settings, random seed, initial state, trajectory, and failure labels in one artifact.
  5. Scale to Isaac Lab or GPU-parallel simulation only after a small model passes deterministic checks.
Evidence Gate

For Numerical integration and stability, compare methods only through one saved artifact that preserves the inputs, outputs, units, timestamps, latency budget, configuration, seed, metric definition, and failure labels relevant to this section. The comparison is meaningful only when the same script evaluates the same panel.

Exercise Extension

Extend the section exercise by adding one perturbation specific to Numerical integration and stability and one latency or uncertainty check. Save the result in the EvidenceRecord schema, then explain which library output you trust and why.

For Numerical integration and stability, distrust smooth simulation until the section-specific physical assumption has been stress-tested: timestep, contact stiffness, damping, friction, actuation, and energy behavior should each have a small diagnostic.

Technical Core

Numerical integration and stability needs a topic-native core: variables, equations or system contracts, an algorithmic procedure, an expected output, and a failure diagnosis. Figure 6.4.T summarizes the chain this section must preserve when moving from a teaching example to a real embodied system.

Technical core for Numerical integration and stability A block diagram connecting assumptions, model, algorithm, evidence, and failure analysis for Numerical integration and stability. Assumptions frames, units, limits Model dynamics and simulation Algorithm update or plan Evidence trace, metric Failure diagnosis Graduate-depth contract: define variables, run the method, interpret output, and explain when it fails. This diagram marks the minimum technical chain the section must make explicit.
Figure 6.4.T: The technical core for Numerical integration and stability connects assumptions, model, algorithm, evidence, and failure analysis.
Formal Object

For $\dot x=f(x,u)$, explicit Euler uses $x_{k+1}=x_k+\Delta t f(x_k,u_k)$. Semi-implicit Euler first updates velocity, then uses the new velocity to update position, which often behaves better for mechanical energy. Runge-Kutta methods reduce local truncation error for smooth motion, while implicit methods trade a nonlinear solve for better behavior on stiff springs, damping, and contact constraints.

Integrator validation recipe
  1. Run the same initial state with $\Delta t$, $\Delta t/2$, and $\Delta t/4$, then compare trajectory, task metric, and energy drift.
  2. Test free motion separately from contact-rich motion so contact solver artifacts do not hide integrator errors.
  3. Record integrator type, internal solver iterations, control update rate, sensor update rate, and substep count.
  4. Reject a policy comparison when a win disappears under timestep refinement or depends on a different integrator setting.
Technical Contract For Numerical integration and stability
Contract FieldWhat To SpecifyWhy It Matters
State and observationVariables, units, timestamps, frames, and uncertainty.Prevents a model score from being mistaken for robot capability.
Action interfaceCommand type, limits, update rate, and safety fallback.Makes the learned or planned output executable.
Evidence artifactTrace, metric, configuration, seed, and failure label.Allows baseline and library path to be compared in one pass.
Tool pathMuJoCo, Drake, Isaac Sim, Gazebo, PyBullet, SAPIEN, NumPyShows the practical library route after the mechanism is understood.

For Numerical integration and stability, expected output is a state trace with the relevant physical invariant: bounded energy error for free motion, bounded penetration for contact, and a solver-status field that explains divergence.

Failure Mode To Test

Numerical integration and stability is validated by conserved quantities where they should hold, stable contact where contact is expected, and reproducible divergence under a named parameter perturbation.

Section References

Core references for Numerical integration and stability: Modern Robotics; Murray, Li, and Sastry; Siciliano et al.; LaValle; and the official documentation for Drake, MuJoCo, Pinocchio, CasADi, python-control, GTSAM, ROS 2, and OpenCV as applicable.

Use these references to check notation, frame conventions, solver assumptions, and library behavior before comparing hand-built and maintained-tool implementations.

Key Takeaway

Numerical integration and stability is useful when it makes the perception-action loop more reliable, not when it merely adds a more impressive model name.

Exercise 6.4.1

Design a method-matched experiment for Numerical integration and stability. Specify the environment, observations, actions, metric, one perturbation, and the library output you would compare against the hand-built baseline.