Validation
Validation answers one question for each model: is the implementation computing what its page says it computes, to a stated tolerance? Checks fall into four levels.
| Level | Compares against | Examples |
|---|---|---|
| Analytic | Closed-form solutions | Free fall, projectile with linear drag, torque-free precession, the intermediate-axis flip, bounce height $e^2 h$, sliding on an incline |
| Numerical | Properties every correct method must have | Measured convergence order, energy and angular-momentum drift, unit-norm preservation on SO(3) |
| Published data and reference code | Measurements and independent implementations | UIUC propeller data, the Crazyflie identification, Aerosonde trim and eigenvalues from BYU’s reference code, the NTNU Skywalker X8 papers |
| Statistical | Spectra and noise statistics | Turbulence power spectra against the Dryden model, IMU noise recovered from Allan deviation |
Every check reports four things:
- Tolerance, and why it suits the step size and model.
- Result: the measured error.
- Pass or fail.
- Known limitations: what the check doesn’t cover.
The tables on this page are generated by mjk validate, so they always match the code that
produced them. The analytic checks below are the first; the full report is
#81.
Analytic checks
These checks run the whole simulation loop, World with RKMK4 at the default 1 kHz, and compare
it with closed-form solutions (#16). The
convergence-order checks run every integrator at four step sizes.
Each tolerance is fixed before the run from an error estimate: ten times the estimate, rounded up to a power of ten. The estimate is printed under the table, so a reader can check that the tolerance suits the step size. A test fails if any check fails, and CI requires the WebAssembly build to print the same table byte for byte.
Closed forms
Free fall from rest under standard gravity, Down positive:
z = \tfrac12 g_0 t^2, \qquad v = g_0 t
\qquad\text{(VAL-1)}
A projectile with linear drag $-c\,\mathbf{v}$, with time constant $\tau = m/c$ and
terminal velocity $\mathbf{v}_t = g_0\tau\,\mathbf{z}_W$, launched from the origin at
$\mathbf{v}_0$:
\mathbf{v}(t) = \mathbf{v}_t + (\mathbf{v}_0 - \mathbf{v}_t)\,e^{-t/\tau}
\qquad\text{(VAL-2)}
\mathbf{x}(t) = \mathbf{v}_t\,t + \tau\,(\mathbf{v}_0 - \mathbf{v}_t)\left(1 - e^{-t/\tau}\right)
\qquad\text{(VAL-3)}
A torque-free axisymmetric body, with transverse and axial moments $I_t$ and $I_a$:
the transverse angular velocity turns in body axes at
\Omega = \frac{(I_a - I_t)\,\omega_3}{I_t}
\qquad\text{(VAL-4)}
the symmetry axis turns around the fixed angular momentum $\mathbf{L}$ at
\dot\phi = \frac{\lvert\mathbf{L}\rvert}{I_t}
\qquad\text{(VAL-5)}
and the attitude, from $\mathbf{R}_0$, is a rotation about $\hat{\mathbf{L}}$ composed with one
about the body’s symmetry axis $\mathbf{e}_3$:
\mathbf{R}(t) = \mathrm{Rot}\!\left(\hat{\mathbf{L}},\ \frac{\lvert\mathbf{L}\rvert t}{I_t}\right)\mathbf{R}_0\,\mathrm{Rot}(\mathbf{e}_3,\ -\Omega t)
\qquad\text{(VAL-6)}
A torque-free body spinning near its intermediate axis, $I_1 < I_2 < I_3$, with angular
momentum $M$ and kinetic energy $E$ such that $M^2 > 2EI_2$. The intermediate-axis rate is
proportional to $\mathrm{sn}(\omega_p t, k)$ (Landau and Lifshitz, §37), so it changes sign, and
the body flips, every
\Delta t = \frac{2K(k)}{\omega_p}, \quad
\omega_p = \sqrt{\frac{(I_3 - I_2)(M^2 - 2EI_1)}{I_1 I_2 I_3}}, \quad
k^2 = \frac{(I_2 - I_1)(2EI_3 - M^2)}{(I_3 - I_2)(M^2 - 2EI_1)}
\qquad\text{(VAL-7)}
with the complete elliptic integral computed by the arithmetic–geometric mean:
K(k) = \frac{\pi}{2\,\mathrm{AGM}\!\left(1, \sqrt{1 - k^2}\right)}
\qquad\text{(VAL-8)}
Convergence order $p$ is the least-squares slope of $\ln e$ against $\ln h$ over
$h = 1/16$ to $1/128$ s, where $e$ is the error against Eq. (VAL-3) for translation and
Eq. (VAL-6) for rotation:
e \approx C\,h^{p}
\qquad\text{(VAL-9)}
Test bodies
| Check | Body | Start | Run |
|---|---|---|---|
| Free fall | 2 kg | at rest | 10 s |
| Linear drag | 2 kg, $c$ = 0.5 N·s/m ($\tau$ = 4 s) | $\mathbf{v}_0$ = (20, 0, −15) m/s | 5 s |
| Axisymmetric body | $I_t$ = 0.02, $I_a$ = 0.035 kg·m² | $\boldsymbol\omega$ = (1, 0, 12) rad/s | 10 s |
| Intermediate axis | $I$ = (0.010, 0.020, 0.030) kg·m² | $\boldsymbol\omega$ = (0.05, 3, 0.05) rad/s; $k'^2 = 5.6\times10^{-4}$ | 60 s |
| Order, translation | 2 kg, $c$ = 2 N·s/m ($\tau$ = 1 s) | $\mathbf{v}_0$ = (2, 0, −1) m/s | 4 s |
| Order, rotation | $I_t$ = 0.02, $I_a$ = 0.035 kg·m² | $\boldsymbol\omega$ = (0.3, 0, 1) rad/s | 4 s |
Results
| # | Check | Closed form | Simulated | Error | Tolerance | Result |
|---|---|---|---|---|---|---|
| 1 | Free fall: distance fallen in 10 s | 490.3325000 | 490.3325000 | 5.3e-11 m | 1e-7 m | Pass |
| 2 | Free fall: speed after 10 s | 98.06650000 | 98.06650000 | 1.3e-11 m/s | 1e-8 m/s | Pass |
| 3 | Linear drag: position after 5 s | 70.49587964 | 70.49587964 | 2.4e-13 m | 1e-9 m | Pass |
| 4 | Linear drag: velocity after 5 s | 24.37355023 | 24.37355023 | 1.4e-14 m/s | 1e-9 m/s | Pass |
| 5 | Axisymmetric body: precession rate in body axes | 9.000000000 | 9.000000000 | 4.9e-10 rad/s | 1e-8 rad/s | Pass |
| 6 | Axisymmetric body: precession rate in space | 21.02379604 | 21.02379604 | 4.9e-10 rad/s | 1e-7 rad/s | Pass |
| 7 | Axisymmetric body: attitude after 10 s | R(t), Eq. (VAL-6) | angle from it | 2.4e-10 rad | 1e-6 rad | Pass |
| 8 | Intermediate axis: time between flips | 5.926982582 | 5.926982582 | 7.1e-13 (relative) | 1e-6 | Pass |
| 9 | Intermediate axis: angular momentum over 60 s | constant | largest change | 3.4e-14 (relative) | 1e-8 | Pass |
| 10 | Intermediate axis: kinetic energy over 60 s | constant | largest change | 7.0e-14 (relative) | 1e-8 | Pass |
| 11 | Convergence order: explicit Euler, translation (linear drag) | 1 | 0.99 | 0.01 | 0.2 | Pass |
| 12 | Convergence order: explicit Euler, rotation (precession) | 1 | 0.99 | 0.01 | 0.2 | Pass |
| 13 | Convergence order: semi-implicit Euler, translation (linear drag) | 1 | 1.00 | 0.00 | 0.2 | Pass |
| 14 | Convergence order: semi-implicit Euler, rotation (precession) | 1 | 0.99 | 0.01 | 0.2 | Pass |
| 15 | Convergence order: RK4, translation (linear drag) | 4 | 4.02 | 0.02 | 0.2 | Pass |
| 16 | Convergence order: RK4, rotation (precession) | 4 | 4.00 | 0.00 | 0.2 | Pass |
| 17 | Convergence order: RKMK4, translation (linear drag) | 4 | 4.02 | 0.02 | 0.2 | Pass |
| 18 | Convergence order: RKMK4, rotation (precession) | 4 | 4.00 | 0.00 | 0.2 | Pass |
Vector checks show magnitudes; their error is the distance between the vectors.
Why each tolerance:
- 1. RKMK4 integrates translation as RK4 does, and RK4’s stages integrate a constant acceleration exactly, so only rounding remains: at most N·ε·z = 1.1e-9 over N = 10000 steps.
- 2. RKMK4 integrates translation as RK4 does, and RK4’s stages integrate a constant acceleration exactly, so only rounding remains: at most N·ε·v = 2.2e-10 over N = 10000 steps.
- 3–4. RKMK4 integrates translation as RK4 does. Its truncation, (T/τ)(h/τ)⁴/120 = 4e-17 of the 231 m transient, is far below rounding over N = 5000 steps, which sets both tolerances: N·ε·|x| = 7.8e-11 m and N·ε·|v| = 2.7e-11 m/s.
- 5. RK4-type phase error over the run, N·(h·ω)⁵/120 divided by T = 10 s, with ω = 9.00 rad/s: 4.9e-10 rad/s.
- 6. RK4-type phase error over the run, N·(h·ω)⁵/120 divided by T = 10 s, with ω = 12.04 rad/s: 2.2e-9 rad/s.
- 7. RK4-type phase error, N·(h·ω)⁵/120 with ω = 12.04 rad/s, plus rounding: 2.2e-8 rad.
- 8. Near the separatrix (k′² = 5.6e-4) an invariant error δ moves the interval by about δ/(2K·k′²) = 175δ; with δ = 1.3e-10, 2.4e-8.
- 9–10. RK4-type truncation N·(h·ω)⁵/120 plus rounding N·ε, with ω = 3.00 rad/s: 1.3e-10.
- 11–18. Slope of ln(error) against ln(h) over h = 1/16 to 1/128 s, for 2 kg with drag 2 N·s/m (τ = 1 s) launched at (2, 0, -1) m/s, and for a body with transverse and axial moments 0.02 and 0.035 kg·m² spinning at (0.3, 0, 1) rad/s. At the largest step h·ω = 0.11 and h/τ = 0.0625: the next term of the error expansion shifts the slope by about that much, and ±0.2 is about twice it.
Generated by mjk validate analytic. A test fails if this table no longer matches the code.
Every error is at or below its estimate. For the body-frame precession the estimate is not
only a bound but the error itself: RK4-type methods drop the $(h\omega)^5/120$ term of
$e^{ih\omega}$ each step, and over 10 000 steps at 9 rad/s that predicts $4.9\times10^{-10}$
rad/s, which is what the run shows. The flip-interval estimate is far above the measured
$7\times10^{-13}$ because it assumes the invariants drift as much as their own estimate allows;
they drift thousands of times less.
The checks have teeth. Tests rerun the physics checks with first-order methods: explicit Euler fails every group, and semi-implicit Euler fails the drag and precession groups. RK4 passes free fall, drag and precession, as a fourth-order method should.
Limitations
- One method at one step. The physics checks use RKMK4 at 1 kHz, the configuration a run uses; the convergence rows cover the other methods.
- The flip check compares the period, not the trajectory. Comparing $
\boldsymbol\omega(t)$ with the Jacobi elliptic functions sn, cn and dn throughout would be stronger. - No coupling between translation and rotation. Each check exercises one; the models that couple them, rotors and aerodynamics, arrive in M2 and M4 with their own validation.
- No contact. Bounce height and sliding on an incline need the contact solver and arrive with it (#55–#61).
Verified so far
The analytic checks above rest on foundations that are tested on their own, each property over hundreds of random inputs and each edge case deterministically:
| Component | What is checked |
|---|---|
| Frame-typed math (#8) | Rotations preserve norms; a quaternion times its inverse is the identity; quaternion composition matches the matrix product; transpose, determinant, inverse and symmetric eigen-decomposition identities; exact results of the elementary operators; eigen-decomposition accuracy independent of scale and of off-diagonal patterns |
| SO(3) maps (#9) | Log inverts Exp for angles from $10^{-12}$ rad to just under $\pi$; Exp inverts Log and takes the short way; Jacobian identities, and the right Jacobian linearizes Exp; plus and minus invert each other; slerp moves at constant rate; Euler angles round-trip, including at gimbal lock; matrix conversion round-trips and non-rotations are rejected; Jacobian coefficients agree with 40-digit references; the small-angle branches of Exp and Log are accurate to within 2 and 4 ulp |
| Rigid-body dynamics (#10) | Composite mass properties against a hand-computed tensor and the shape formulas; cutting a component in half or rotating every component leaves the result consistent; Euler’s equations against their principal-axis closed form; power balance and conservation of angular momentum hold for any state, inertia and loads |
| Integrators (#11, #12) | Each method against its closed form under constant acceleration; RK4 exact for cubic rates; RKMK4 exact for steady principal-axis spin; measured order 1, 1, 4 and 4 (within ±0.2) on an oscillator and on a tumbling body; semi-implicit Euler energy bounded over 10⁶ steps while explicit Euler’s grows as predicted; RKMK4 keeps a unit quaternion with no renormalization; the RK4-against-RKMK4 study table is generated by mjk validate and checked against the code |
| Motor and ESC (#19) | Steady speed under constant and propeller loads against the closed forms to 10⁻¹¹ rad/s; the small-signal time constant within 5.3 × 10⁻⁴ of the linearized one; the lag tier’s time constant; ESC latency and slew exact to the tick; coasting, active braking and a current-limited start against their closed forms; the power balance; every equation, braking mode and limit unit-tested; an ESC update allocates nothing; the table is generated by mjk validate motor |
| Atmosphere and gravity (#15) | Temperature, pressure, density, speed of sound and viscosity match the 1976 standard’s printed tables at 0, 1, 2, 5, 11 and 20 km to four significant figures (largest gap 0.10 of a unit in the fourth figure), in a table generated by mjk validate atmosphere; the air is continuous at the tropopause and in hydrostatic balance with any temperature offset; WGS-84 normal gravity matches the exact field of the level ellipsoid to $1.5\times10^{-6}$ m/s² from −5 to 20 km, and its derived constants, computed from the four defining parameters, match the printed tables of the WGS-84 standard (NGA.STND.0036) to the last digit |
| World loop (#13) | Every subsystem runs exactly at its rate over 10 s (500, 250, 50 and 10 Hz at 1 kHz); sensors run before controllers within a tick; commands are held between controller updates; time is exact at tick 123 456 789; the real-time accumulator carries remainders and drops a backlog it cannot catch up on; two runs are identical to the bit; a step allocates nothing |
| Determinism and replay (#14) | SplitMix64, xoshiro256** and FNV-1a match their published reference algorithms; adding a random stream leaves the others unchanged; no two seed-and-name pairs share a stream, no state word is shared within a run, and streams start with different draws and are uncorrelated (weekly, PractRand on interleaved streams to 32 GB); uniform and normal samples have the right values and moments; two runs of the reference scenario are identical at every checkpoint; replaying its recorded inputs reproduces the final hash; changing one input changes every hash from its tick on; a WebAssembly build prints the same tables as the native build, byte for byte; recording and replay allocate nothing |
| Analytic suite (#16) | Free fall, linear drag, torque-free precession and the intermediate-axis flip through the whole simulation loop, each within a tolerance fixed beforehand from an error estimate; measured order 1, 1, 4 and 4 (within ±0.2) for every integrator on drag and precession; first-order methods fail the physics checks; the table is generated by mjk validate analytic |
| Inertia consistency (#7) | Non-finite, asymmetric, indefinite and triangle-inequality-violating tensors are rejected, with each principal minor and its tolerance pinned by a case only it can detect (Engineering standards) |
| Configuration files (#7, #18) | Each of 23 malformed sample files produces an error naming the exact field at fault, among them a number without a unit, a unit of the wrong quantity, a source not in the bibliography, too little thrust and overlapping rotor disks; a number without a source loads with a warning; every unit symbol converts by its definition; each airframe’s generated page matches its file, natively and in WebAssembly |
These are unit and property tests, and their tolerances are stated in the tests. The generated report (#81) will tabulate model checks in the format above.
How the tests are checked
Two gates in CI measure the tests themselves. Engine line coverage must stay at or above 90 %. Mutation testing changes the code in small ways and fails if any change goes unnoticed by every test; no mutant of the engine survives. Both are described on the Engineering standards page.