Describe motion with scalar energy
Kinetic energy measures motion; potential energy measures stored conservative energy. Their difference is the Lagrangian:
For many rigid mechanisms, kinetic energy is quadratic in generalized velocity:
The mass matrix is configuration-dependent because changing joint angles rearranges the moving mass. It must be symmetric positive definite for independent coordinates with positive masses.
Euler–Lagrange turns energy into motion
For coordinate and applied generalized force :
This is not a different physics from Newton's laws. It packages the same mechanics in coordinates that already respect the mechanism's joints, so internal ideal constraint forces disappear from the final coordinate equations.
Experiment 1: derive and integrate a pendulum
Let angle be measured from hanging down, with point mass , length , and gravity magnitude :
Applying Euler–Lagrange produces the nonlinear pendulum:
Integrate the nonlinear pendulum
Does an accurate integrator preserve the energy used to derive the equation?
def derivative(state):
theta, omega = state
return np.array([omega, -(g / length) * np.sin(theta)])
Expected result: oscillation is slightly slower than the small-angle model at finite amplitude. Failure modes: use degrees inside sin, choose potential energy with the wrong sign, or compare numerical energy error to physical damping.
- Expected result
- The command exits successfully and reproduces the numerical or visual relationship described in this card.
- Failure modes
- Non-finite values, a reversed trend, a failed assertion, or a materially different plot means the assumptions, seed, timestep, build, or backend should be inspected before continuing.
The reusable robot equation
Applying Euler–Lagrange to every coordinate and grouping terms yields:
maps acceleration to inertial torque. collects velocity-dependent Coriolis and centrifugal terms. is the gravity torque. contains applied generalized forces. Some texts use a matrix ; here names the already-multiplied vector.
Experiment 2: inspect the two-link mass matrix
Sweep inertia through configuration
Can the mass matrix change while remaining a valid kinetic-energy metric?
The reference model places masses at the ends of two massless links. One entry is:
The off-diagonal entries encode dynamic coupling: accelerating one joint can require torque at the other.

Failure modes: drop one coupling term, use a negative mass, or accidentally build a non-symmetric matrix. The tests sweep the workspace instead of checking one friendly pose.
- Expected result
- The command exits successfully and reproduces the numerical or visual relationship described in this card.
- Failure modes
- Non-finite values, a reversed trend, a failed assertion, or a materially different plot means the assumptions, seed, timestep, build, or backend should be inspected before continuing.
Experiment 3: cancel gravity without feedback
At rest, and desired . The necessary holding torque is simply:
Plot gravity-compensation torque
Why is one constant motor torque unable to hold an arm everywhere?

The executable assertion feeds into forward dynamics at zero velocity and obtains zero acceleration within 1e-12.
Failure modes: omit the downstream link from shoulder torque, use the controller target instead of measured configuration, or treat gravity compensation as feedback—it is model-based feedforward.
- Expected result
- The command exits successfully and reproduces the numerical or visual relationship described in this card.
- Failure modes
- Non-finite values, a reversed trend, a failed assertion, or a materially different plot means the assumptions, seed, timestep, build, or backend should be inspected before continuing.
Forward and inverse dynamics should agree
Inverse dynamics asks for torque given desired acceleration:
Forward dynamics asks for acceleration given torque:
In code, solve the linear system rather than explicitly forming the inverse:
qdd = np.linalg.solve(M, torque - velocity_terms - gravity)
torque = M @ desired_qdd + velocity_terms + gravityThe Chapter 5 test sends through inverse dynamics and back through forward dynamics. The recovered acceleration error is below 1e-15.
Experiment 4: compare a Cartesian constrained pendulum
Measure LavenderSim's pendulum period
Does a Cartesian joint-constraint model recover the generalized-coordinate prediction?
A sphere begins 0.5 rad from downward and is attached to the world by a passive revolute joint. Its angle is measured geometrically from the bob position rather than copied from the reference model.
The finite amplitude increases period; the native bob also has finite rotational inertia, constraint projection, and built-in damping. Agreement in trend and period is the meaningful comparison—not pointwise identity.
substep() instead applies Cartesian forces, solves joint/contact impulses, integrates body poses, and projects constraints.- Expected result
- The command exits successfully and reproduces the numerical or visual relationship described in this card.
- Failure modes
- Non-finite values, a reversed trend, a failed assertion, or a materially different plot means the assumptions, seed, timestep, build, or backend should be inspected before continuing.
Paw-check: make energy do useful work
- Add viscous pendulum damping and verify that energy decreases monotonically.
- Derive the physical-pendulum equation by adding center-of-mass inertia.
- Numerically differentiate potential energy and compare it with .
- Plot mass-matrix condition number across elbow angle.
- Add an external tip force using .
- Vary the native solver iterations and timestep; separate period change from constraint error.
What should I be able to say now?
The Lagrangian is kinetic minus potential energy. Euler–Lagrange converts it into coordinate dynamics. Robot equations organize inertia, velocity coupling, gravity, and applied torque. A valid mass matrix is symmetric positive definite; gravity compensation is configuration-dependent feedforward; and forward/inverse dynamics provide a powerful consistency test. LavenderSim reaches similar physical motion through Cartesian body integration and numerical constraints rather than storing generalized coordinates as its primary state.