rigid_body_spin
Torque-free rotation of a rigid body: Euler's equations in the principal body frame, integrated by classical RK4. Gives the angular velocity history, the conserved rotational energy and angular momentum and how far RK4 drifted from them, the polhode (body-frame precession) period by the Jacobi-elliptic closed form and as measured from the history, the body- and space-frame precession rates of an axisymmetric body, and for steady spin about each principal axis whether it is stable, with the wobble or growth rate by the linearised closed form and as measured by a perturbed RK4 probe. The body is given by its three principal moments or as a uniform box. Writes out/trace.csv and out/stability.csv.
- Field
- Dynamics and control
- Version
- 0.1.0
- Runs as
- Compiled (Rust)
- Typical run
- 0.1 s
Compiled from source: run sh packs/install.sh once before admitting it.
Known answers it must pass
r0001axisymmetric body I=(2,2,3), w=(0.1,0,1): body-frame precession (I3-I1)/I1*w3 = 0.5 rad/s, period 4 pi; after two periods (8 pi s) w returns to its start (Goldstein, free symmetric top). RK4 tolerance 1e-8 at h = 2.5e-4 spassed
body_precession_rate_rad_per_s0.5 ± 5e-130.5lockedunder 0.01 % of the tolerance usedprecession_rate_measured_rad_per_s0.5 ± 5e-070.5lockedunder 0.01 % of the tolerance usedpolhode_period_s12.5664 ± 1.3e-0812.5664lockedunder 0.01 % of the tolerance usedspace_precession_rate_rad_per_s1.50333 ± 1.5e-091.50333lockedunder 0.01 % of the tolerance usedenergy_J1.51 ± 1.5e-121.51lockedunder 0.01 % of the tolerance usedangular_momentum_kg_m2_per_s3.00666 ± 3e-123.00666locked0.015 % of the tolerance usedomega1_final_rad_per_s0.1 ± 1e-080.1lockedunder 0.01 % of the tolerance usedomega2_final_rad_per_s0 ± 1e-081.81499e-16lockedunder 0.01 % of the tolerance usedomega3_final_rad_per_s1 ± 1e-121lockedunder 0.01 % of the tolerance usedenergy_drift_rel≤ 1e-100lockedinside the rangeangular_momentum_drift_rel≤ 1e-100lockedinside the ranger0002sphere I=(2.5,2.5,2.5): Euler's equations give zero rate of change, so the angular velocity never moves; E = I|w|^2/2 = 2.1125 J, L = I|w| = 3.25passed
omega_max_change_rad_per_s0 ± 1e-140lockedunder 0.01 % of the tolerance usedomega1_final_rad_per_s0.3 ± 1e-140.3lockedunder 0.01 % of the tolerance usedomega2_final_rad_per_s-0.4 ± 1e-14-0.4lockedunder 0.01 % of the tolerance usedomega3_final_rad_per_s1.2 ± 1e-141.2lockedunder 0.01 % of the tolerance usedenergy_J2.1125 ± 2.1e-122.1125lockedunder 0.01 % of the tolerance usedangular_momentum_kg_m2_per_s3.25 ± 3.3e-123.25lockedunder 0.01 % of the tolerance usedunstable_axis= lockedexact matchregime= spherespherelockedexact matchr0003triaxial I=(1,2,3), w=(sqrt 3, 0, sqrt 2): modulus k^2 = 1/2 exactly, so the polhode period is 4 K / sqrt 2 with K(1/2) = Gamma(1/4)^2 / (4 sqrt pi) = 1.8540746773013719 (lemniscatic value), T = 5.244115108584239 s (Landau & Lifshitz section 37); E = 4.5 J, L = sqrt 21. Measured period 1e-6: linear interpolation of zero crossings at h = 1e-3 spassed
polhode_period_s5.24412 ± 5.2e-095.24412lockedunder 0.01 % of the tolerance usedpolhode_period_measured_s5.24412 ± 5.2e-065.24412lockedunder 0.01 % of the tolerance usedenergy_J4.5 ± 4.5e-124.5lockedunder 0.01 % of the tolerance usedangular_momentum_kg_m2_per_s4.58258 ± 4.6e-124.58258locked0.019 % of the tolerance usedpolhode_circles_axis= 33lockedexact matchenergy_drift_rel≤ 1e-092.86191e-14lockedinside the rangeangular_momentum_drift_rel≤ 1e-091.27919e-14lockedinside the ranger0004I=(1,2,3), w=(0,1,0.01) so |w| = sqrt 1.0001: linearised Euler equations for steady spin at |w| give growth rate |w| sqrt((I2-I1)(I3-I2)/(I1 I3)) = sqrt(1.0001/3) about axis 2 and wobble rates |w| sqrt((Ia-Ij)(Ia-Ik)/(Ij Ik)) = sqrt(1.0001/3) (axis 1) and sqrt 1.0001 (axis 3); the spin near axis 2 leaves it (flips past 90 deg), a kick about axes 1 and 3 stays at its size (amplification 1). Measured rates 1e-3: linear theory read from a finite 1e-6 kickpassed
unstable_axis= 22lockedexact matchspin_stable= falsefalselockedexact matchmax_axis_deviation_deg90 to 180178.854lockedinside the rangestability.axis_2.kind= unstablemisseddiffersomega0_rad_per_s1.00005 ± 1e-121.00005lockedunder 0.01 % of the tolerance usedstability.axis_2.rate_closed_rad_per_s{"value": 0.5773791359814334, "rel_tol": 1e-09}stability.axis_2.rate_measured_rad_per_s{"value": 0.5773791359814334, "rel_tol": 0.001}stability.axis_2.amplification{"min": 1000.0}stability.axis_1.kind= stablemisseddiffersstability.axis_1.rate_measured_rad_per_s{"value": 0.5773791359814334, "rel_tol": 0.001}stability.axis_1.amplification{"value": 1.0, "rel_tol": 1e-06}stability.axis_3.kind= stablemisseddiffersstability.axis_3.rate_measured_rad_per_s{"value": 1.0000499987500624, "rel_tol": 0.001}stability.axis_3.amplification{"value": 1.0, "rel_tol": 1e-06}energy_drift_rel≤ 1e-091.68729e-14lockedinside the ranger0005uniform box 1.2 kg, 0.1 x 0.2 x 0.4 m: I = m (b^2 + c^2) / 12 gives (0.02, 0.017, 0.005) kg m^2 (textbook cuboid); the intermediate axis is axis 2 (y), growth rate at 10 rad/s = 10 sqrt((0.003)(0.012)/(0.02*0.005)) = 6 rad/spassed
I1_kg_m20.02 ± 2e-140.02locked0.017 % of the tolerance usedI2_kg_m20.017 ± 1.7e-140.017locked0.02 % of the tolerance usedI3_kg_m20.005 ± 5e-150.005locked0.017 % of the tolerance usedunstable_axis= 22lockedexact matchstability.axis_2.rate_closed_rad_per_s{"value": 6.0, "rel_tol": 1e-09}stability.axis_2.rate_measured_rad_per_s{"value": 6.0, "rel_tol": 0.001}spin_stable= truetruelockedexact matchenergy_J1 ± 1e-121locked0.022 % of the tolerance usedomega_max_change_rad_per_s0 ± 1e-120lockedunder 0.01 % of the tolerance usedr0006I=(3,2,1), steady spin 2 rad/s about axis 3 (smallest moment): linearised wobble rate w sqrt((I3-I1)(I3-I2)/(I1 I2)) = 2/sqrt 3, so the small-wobble polhode period is 2 pi sqrt 3 / 2 = pi sqrt 3 (k -> 0, K = pi/2); the wobble is an ellipse with axis ratio sqrt(I1 (I3-I1) / (I2 (I3-I2))) = sqrt 3, so a kick about axis 1 grows to sqrt 3 times its size and no further; axis 1 wobbles at 2 sqrt((3-2)(3-1)/(2*1)) = 2 rad/s; axis 2 grows at 2 sqrt((3-2)(2-1)/(3*1)) = 2/sqrt 3. Amplification 1e-5: the peak is read from 2000 samples per wobblepassed
polhode_period_s5.4414 ± 5.4e-095.4414lockedunder 0.01 % of the tolerance usedpolhode_circles_axis= 33lockedexact matchregime= smallestsmallestlockedexact matchstability.axis_3.kind= stablemisseddiffersstability.axis_3.rate_closed_rad_per_s{"value": 1.1547005383792517, "rel_tol": 1e-09}stability.axis_3.rate_measured_rad_per_s{"value": 1.1547005383792517, "rel_tol": 1e-06}stability.axis_3.amplification{"value": 1.7320508075688772, "rel_tol": 1e-05}stability.axis_3.wobble_amplification_closed{"value": 1.7320508075688772, "rel_tol": 1e-09}stability.axis_1.rate_closed_rad_per_s{"value": 2.0, "rel_tol": 1e-09}stability.axis_1.rate_measured_rad_per_s{"value": 2.0, "rel_tol": 1e-06}stability.axis_2.kind= unstablemisseddiffersstability.axis_2.rate_closed_rad_per_s{"value": 1.1547005383792517, "rel_tol": 1e-09}unstable_axis= 22lockedexact matchspin_stable= truetruelockedexact matchenergy_J2 ± 2e-122lockedunder 0.01 % of the tolerance usedangular_momentum_kg_m2_per_s2 ± 2e-122lockedunder 0.01 % of the tolerance usedr0007scale check, I=(1,2,3)e-300 kg m^2, w=(sqrt 3, 0, sqrt 2): Euler's equations hold only ratios of the moments, so the period is the same T = 4 K(1/2) / sqrt 2 = 5.244115108584239 s as for I=(1,2,3) (Landau & Lifshitz section 37) and the stability rates are |w| sqrt(1/3) and |w| with |w| = sqrt 5passed
polhode_period_s5.24412 ± 5.2e-095.24412lockedunder 0.01 % of the tolerance usedpolhode_period_measured_s5.24412 ± 5.2e-065.24412lockedunder 0.01 % of the tolerance usedpolhode_circles_axis= 33lockedexact matchunstable_axis= 22lockedexact matchstability.axis_2.rate_closed_rad_per_s{"value": 1.2909944487358056, "rel_tol": 1e-09}stability.axis_3.rate_closed_rad_per_s{"value": 2.23606797749979, "rel_tol": 1e-09}stability.axis_3.kind= stablemisseddiffers
Each line is one reading the kernel checked. The bright band is the tolerance; the needle is the value the instrument actually returned when it was admitted. A needle near the centre line used little of its tolerance.
Inputs
| Name | Unit | Default | Meaning |
|---|---|---|---|
body | moments | "moments": give I1_kg_m2, I2_kg_m2, I3_kg_m2. "box": a uniform rectangular block, give mass_kg and size_x_m, size_y_m, size_z_m (axis 1 is x, 2 is y, 3 is z). | |
I1_kg_m2 | kg m^2 | 1.0 | Principal moment of inertia about body axis 1. |
I2_kg_m2 | kg m^2 | 2.0 | Principal moment of inertia about body axis 2. |
I3_kg_m2 | kg m^2 | 3.0 | Principal moment of inertia about body axis 3. |
mass_kg | kg | 1.0 | Box only: mass. |
size_x_m | m | 0.1 | Box only: edge along body axis 1. |
size_y_m | m | 0.2 | Box only: edge along body axis 2. |
size_z_m | m | 0.3 | Box only: edge along body axis 3. |
omega1_rad_per_s | rad/s | 0.0 | Initial angular velocity about body axis 1. |
omega2_rad_per_s | rad/s | 0.01 | Initial angular velocity about body axis 2. |
omega3_rad_per_s | rad/s | 1.0 | Initial angular velocity about body axis 3. |
duration_s | s | 60.0 | How long to integrate. |
steps | 1 | 60000 | RK4 steps over duration_s. |
perturbation | 1 | 1e-06 | Stability probe: the sideways kick given to steady spin about each axis, as a fraction of the spin rate. |
Readings
| Name | Unit | Meaning |
|---|---|---|
body | 1 | |
I1_kg_m2 | kg m^2 | |
I2_kg_m2 | kg m^2 | |
I3_kg_m2 | kg m^2 | |
omega0_rad_per_s | rad/s | initial spin rate |omega| |
energy_J | J | rotational kinetic energy at the start, (I1 w1^2 + I2 w2^2 + I3 w3^2)/2 |
angular_momentum_kg_m2_per_s | kg m^2/s | |L| at the start |
energy_drift_rel | 1 | largest relative change of the energy over the RK4 history |
angular_momentum_drift_rel | 1 | largest relative change of |L| over the RK4 history |
omega1_final_rad_per_s | rad/s | |
omega2_final_rad_per_s | rad/s | |
omega3_final_rad_per_s | rad/s | |
omega_min_rad_per_s | rad/s | lowest value of each body-frame component over the history |
omega_max_rad_per_s | rad/s | highest value of each body-frame component over the history |
omega_max_change_rad_per_s | rad/s | largest distance of the body-frame angular velocity from its start |
max_axis_deviation_deg | deg | largest angle between the body-frame angular velocity and its start |
polhode_period_s | s | closed form 4 K(k) / lambda (Landau & Lifshitz, Mechanics, section 37); for spin exactly about the largest or smallest axis it is the period of a vanishingly small wobble; null for a sphere, on the separatrix (which includes spin exactly about the intermediate axis) and for spin in the plane of two equal moments |
polhode_period_measured_s | s | from zero crossings of the intermediate-axis component in the RK4 history |
polhode_period_rel_error | 1 | |
precession_rate_rad_per_s | rad/s | 2 pi / polhode_period_s |
precession_rate_measured_rad_per_s | rad/s | |
body_precession_rate_rad_per_s | rad/s | axisymmetric body only: (I_axis - I_side) / I_side * omega_axis, signed; null otherwise |
space_precession_rate_rad_per_s | rad/s | axisymmetric body only: |L| / I_side, the rate the symmetry axis cones about L |
polhode_circles_axis | 1 | 1, 2 or 3: the principal axis the angular velocity circles in the body |
regime | 1 | largest or smallest: the principal axis the angular velocity circles; separatrix: on the dividing line (includes spin exactly about the intermediate axis); steady: spin in the plane of two equal moments, it does not move; sphere |
nearest_axis | 1 | |
start_off_axis_deg | deg | |
unstable_axis | 1 | the intermediate axis, or null when two moments are equal |
spin_stable | 1 | false when the largest component of the starting spin is about the intermediate axis; a rule of thumb, read max_axis_deviation_deg for what the spin actually did |
stability | steady spin at omega0 about each principal axis: kind (stable, unstable, or neutral when the axis is one of two equal moments: a kick then neither oscillates nor grows exponentially, it can drift in proportion to time), closed-form and measured rate, measured growth of the kick | |
steps | 1 | |
step_s | s | |
duration_s | s |
Try the call
Change a value and the command updates. Nothing runs here; paste it into your terminal or give it to your agent.