| name | classical-mechanics |
| description | Newtonian mechanics including Lagrangian and Hamiltonian dynamics, central forces, rigid body motion, small oscillations, and chaos theory for physics applications. |
| category | physics |
| tags | ["physics","classical-mechanics","newtonian","lagrangian","hamiltonian","rigid-body","oscillations","chaos"] |
| difficulty | intermediate |
| author | neuralblitz |
Classical Mechanics
What I do
I provide comprehensive expertise in classical mechanics, the branch of physics describing the motion of macroscopic objects. I enable you to apply Newtonian mechanics, Lagrangian and Hamiltonian formalisms, analyze central force motion, study rigid body dynamics, solve small oscillation problems, and explore chaotic systems. My knowledge spans from Newton's laws to advanced analytical mechanics essential for engineering, astrophysics, robotics, and physics education.
When to use me
Use classical mechanics when you need to: analyze projectile and orbital motion, design and control mechanical systems, study pendulum and vibrational dynamics, model rigid body rotation and gyroscopic effects, compute celestial mechanics and orbital transfers, analyze stability of mechanical equilibria, simulate multi-body dynamics, or apply Hamiltonian mechanics for quantum-classical correspondence.
Core Concepts
- Newton's Laws: Foundation of classical mechanics relating forces to acceleration (F=ma) with action-reaction pairs.
- Lagrangian Mechanics: Reformulation using generalized coordinates and the principle of least action (L = T - V).
- Hamiltonian Mechanics: Phase space formulation with Hamilton's equations describing time evolution.
- Conservation Laws: Symmetries leading to conserved quantities (energy, momentum, angular momentum via Noether's theorem).
- Central Forces: Forces directed toward a fixed point enabling reduction to effective one-body problems.
- Rigid Body Motion: Rotation with angular velocity, inertia tensors, and Euler's equations.
- Small Oscillations: Linearization near equilibria to find normal modes and frequencies.
- Canonical Transformations: Changes of variables preserving Hamiltonian structure and Poisson brackets.
- Action-Angle Variables: Specialized coordinates for integrable systems with periodic motion.
- Chaos and Sensitivity: Deterministic unpredictability in nonlinear systems with sensitive dependence on initial conditions.
Code Examples
Newtonian Mechanics
import numpy as np
def newton_motion(F, m, r0, v0, t_span, dt=0.01):
"""
Integrate equations of motion using Velocity Verlet.
F(t, r, v) = ma
"""
n = int((t_span[1] - t_span[0]) / dt)
t = np.linspace(t_span[0], t_span[1], n + 1)
r = np.zeros((n + 1, len(r0)))
v = np.zeros((n + 1, len(v0)))
r[0] = r0
v[0] = v0
for i in range(n):
a = F(t[i], r[i], v[i]) / m
r[i + 1] = r[i] + v[i] * dt + 0.5 * a * dt**2
a_new = F(t[i + 1], r[i + 1], v[i]) / m
v[i + 1] = v[i] + 0.5 * (a + a_new) * dt
return t, r, v
def gravity(t, r, v):
"""Gravitational acceleration (downward)."""
return np.array([0, 0, -9.81])
r0 = np.array([0, 0, 0])
v0 = np.array([10, 0, 20])
t, r, v = newton_motion(gravity, 1, r0, v0, (0, 5), dt=)
mask = r[:, ] >=
range_idx = np.where(np.diff(np.sign(r[mask, ])))[]
max_height = np.(r[:, ])
()
()
()
()
v0x, v0z = ,
g =
t_flight = * v0z / g
range_theory = v0x * t_flight
h_max = v0z** / ( * g)
()
()
()
()
Lagrangian Mechanics
import numpy as np
from scipy.optimize import minimize
def lagrange_equations(L, generalized_coords, generalized_vels, t):
"""
Compute Euler-Lagrange equations.
d/dt(∂L/∂q̇) - ∂L/∂q = 0
"""
from sympy import symbols, diff, Function
pass
def double_pendulum_derivatives(state, m1=1, m2=1, L1=1, L2=1, g=9.81):
"""
Equations of motion for double pendulum.
state = [theta1, theta2, omega1, omega2]
"""
t1, t2, w1, w2 = state
dt = t2 - t1
denom = 2 * m1 + m2 - m2 * np.cos(2 * t1 - 2 * t2)
alpha1 = (-g * (2 * m1 + m2) * np.sin(t1)
- m2 * g * np.sin(t1 - 2 * t2)
- 2 * np.sin(dt) * m2 * (w2**2 * L2 + w1**2 * L1 * np.cos(dt))) / (L1 * denom)
alpha2 = (2 * np.sin(dt)
* (w1**2 * L1 * (m1 + m2) + g * (m1 + m2) * np.cos(t1)
+ w2**2 * L2 * m2 * np.cos(dt))) / (L2 * denom)
return np.array([w1, w2, alpha1, alpha2])
def double_pendulum_energy(state, m1=, m2=, L1=, L2=, g=):
t1, t2, w1, w2 = state
T1 = * m1 * (L1** * w1**)
T2 = * m2 * ((L1** * w1** + L2** * w2**
+ * L1 * L2 * w1 * w2 * np.cos(t1 - t2)))
y1 = -L1 * np.cos(t1)
y2 = y1 - L2 * np.cos(t2)
V = m1 * g * y1 + m2 * g * y2
T1 + T2 + V
state0 = [np.pi/, np.pi/, , ]
dt =
n_steps =
states = [state0]
energies = [double_pendulum_energy(state0)]
_ (n_steps):
state = states[-]
k1 = double_pendulum_derivatives(state)
k2 = double_pendulum_derivatives(state + * dt * k1)
k3 = double_pendulum_derivatives(state + * dt * k2)
k4 = double_pendulum_derivatives(state + dt * k3)
state_new = state + (dt / ) * (k1 + *k2 + *k3 + k4)
states.append(state_new)
energies.append(double_pendulum_energy(state_new))
states = np.array(states)
energies = np.array(energies)
()
()
()
()
()
Hamiltonian Mechanics
import numpy as np
def hamilton_equations(H, state, t=0):
"""
Compute Hamilton's equations.
q̇ = ∂H/∂p
ṗ = -∂H/∂q
"""
q = state[:len(state)//2]
p = state[len(state)//2:]
dqdt = np.gradient(H(state + np.eye(len(state))[-1], q, p), q)
dpdt = -np.gradient(H(state, q + np.eye(len(state))[0], p), p)
return np.concatenate([dqdt, dpdt])
def harmonic_hamiltonian(state, k=1, m=1):
"""H = p²/2m + kx²/2"""
x, p = state
return p**2 / (2 * m) + k * x**2 / 2
x, p = 1.0, 0.5
state = np.array([x, p])
print("Harmonic oscillator (H = p²/2m + kx²/2):")
print(f" H(x=1, p=0.5) = {harmonic_hamiltonian(state):.4f}")
print(f" Expected: p/m = {p/1:.4f}, -kx = {-k*x:.4f}")
def polar_to_cartesian():
r, pr, theta, ptheta = r_p_theta
np.array([
r * np.cos(theta),
pr * np.cos(theta) - ptheta * np.sin(theta) / r,
r * np.sin(theta),
pr * np.sin(theta) + ptheta * np.cos(theta) / r
])
():
numpy gradient
dA_dq = gradient(A(q, p), q)
dA_dp = gradient(A(q, p), p)
dB_dq = gradient(B(q, p), q)
dB_dp = gradient(B(q, p), p)
dA_dq * dB_dp - dA_dp * dB_dq
():
x, px, y, py = q[], p[], q[], p[]
x * py - y * px
():
q[]** + q[]**
q = np.array([, ])
p = np.array([, ])
()
()
()
Rigid Body Motion
import numpy as np
from scipy.linalg import expm, eigh
def inertia_tensor(masses, positions):
"""
Compute inertia tensor I.
I_ij = Σ_m (r²δ_ij - r_i r_j)
"""
I = np.zeros((3, 3))
for m, r in zip(masses, positions):
r = np.array(r)
I += m * (np.dot(r, r) * np.eye(3) - np.outer(r, r))
return I
def principal_axes(I):
"""Diagonalize inertia tensor to find principal moments and axes."""
eigenvalues, eigenvectors = eigh(I)
return eigenvalues, eigenvectors
def euler_equations(tau, omega, I):
"""
Euler's equations for rigid body rotation.
I·α + ω × (I·ω) = τ
"""
I_omega = I @ omega
torque = np.cross(omega, I_omega)
return tau - torque
def rotation_from_euler(phi, theta, psi):
"""
Compute rotation matrix from Euler angles (ZYZ convention).
"""
c1, s1 = np.cos(phi), np.sin(phi)
c2, s2 = np.cos(theta), np.sin(theta)
c3, s3 = np.cos(psi), np.sin(psi)
R = np.array([
[c1*c2*c3 - s1*s3, -c1*c2*s3 - s1*c3, c1*s2],
[s1*c2*c3 + c1*s3, -s1*c2*s3 + c1*c3, s1*s2],
[-s2*c3, s2*s3, c2]
])
return R
masses = [1, 1, 1, 1]
positions = [[-1, -0.5, 0], [1, -0.5, ], [, , ], [-, , ]]
I = inertia_tensor(masses, positions)
moments, axes = principal_axes(I)
()
()
()
()
()
()
()
i, (m, ax) ((moments, axes.T)):
()
():
scipy.integrate solve_ivp
():
euler_equations(np.zeros(), omega, I)
sol = solve_ivp(euler_free, t_span, omega0, method=,
t_eval=np.arange(t_span[], t_span[], dt))
sol.t, sol.y
I_prolate = np.diag([, , ])
omega0 = [, , ]
t, omega = free_rotation_sim(I_prolate, omega0, (, ))
()
()
()
Small Oscillations and Normal Modes
import numpy as np
from scipy.linalg import eigh
def normal_modes(T_matrix, V_matrix):
"""
Find normal modes for small oscillations.
Solve: (V - ω²T)v = 0
"""
eigenvalues, eigenvectors = eigh(V_matrix, T_matrix)
sorted_idx = np.argsort(eigenvalues)
return np.sqrt(eigenvalues[sorted_idx]), eigenvectors[:, sorted_idx]
def triple_mass_spring(m=1, k=1):
"""
Three masses connected by springs.
| k -2k k |
T = diag(m, m, m)
V = | k -2k k |
| k k -2k|
"""
T = np.diag([m, m, m])
K = np.array([
[2*k, -k, 0],
[-k, 2*k, -k],
[0, -k, 2*k]
])
return T, K
T, K = triple_mass_spring()
frequencies, modes = normal_modes(T, K)
print("Triple mass-spring system normal modes:")
for i, (freq, mode) in enumerate(zip(frequencies, modes.T)):
print(f" Mode {i+1}: ω = {freq:.4f}")
print(f" Shape: [{mode[0]:+.3f}, {mode[1]:+.3f}, {mode[]:+f}]")
()
()
()
()
():
omega0_sq = g / L
coupling = k / m
T = np.diag([m*L**, m*L**])
K = m * np.array([
[omega0_sq + coupling, -coupling],
[-coupling, omega0_sq + coupling]
]) * L**
T, K
T_coupled, K_coupled = coupled_pendula()
freqs_coupled, modes_coupled = normal_modes(T_coupled, K_coupled)
()
i, (freq, mode) ((freqs_coupled, modes_coupled.T)):
phase = mode[] * mode[] >
()
():
m1, m2, m3 = masses
T = np.diag([m1, m2, m3])
K = k_stretch * np.array([
[, -, ],
[-, , -],
[, -, ]
])
T, K
masses = [, , ]
T_mol, K_mol = linear_triatomic(masses, , )
freqs_mol, modes_mol = normal_modes(T_mol, K_mol)
()
i, (freq, mode) ((freqs_mol, modes_mol.T)):
()
()
Best Practices
- Choose appropriate generalized coordinates that reflect system symmetries to simplify equations.
- Verify conservation laws (energy, momentum, angular momentum) numerically as sanity checks.
- For Hamiltonian systems, use symplectic integrators (like Velocity Verlet) to preserve phase space volume.
- When linearizing for small oscillations, ensure the equilibrium is stable before finding normal modes.
- For rigid body dynamics, always use principal axes to simplify Euler's equations.
- Be aware of gimbal lock in Euler angles; use quaternions for full SO(3) rotations.
- For chaotic systems, use high-precision arithmetic and validate sensitivity to initial conditions.
- In Lagrangian mechanics, ensure the Lagrangian is a scalar under coordinate transformations.
- When applying Noether's theorem, identify continuous symmetries to find corresponding conserved quantities.
- For numerical integration, choose step sizes small enough to resolve the fastest time scale in the system.