Home / Science / Physics / Classical mechanics / Lagrangian helperTool #908

Euler-Lagrange equation calculator: type T and V, get the equations of motion, momenta and energy

Type the kinetic and potential energy of a system in your own coordinates and get the Lagrangian, the generalised momenta, every Euler-Lagrange equation (simplified, with sin² + cos² = 1), the accelerations or the mass-matrix form, the energy function, and a numerical run that checks energy conservation.

Keep it one tap away for everyday use.

Bookmark Lagrangian helper?

Press Ctrl + D now. Your browser opens its own bookmark box, where you choose the name and folder.

  1. T and V
  2. Derivatives
  3. Equations
  4. Run it
Nothing is uploadedWorks offline once open

System

Write the rate of change of a coordinate with a dash, theta' (or thetadot); time is t. Any other name (m, g, l, k ...) is a constant. Use + − * / ^ and brackets, and sin, cos, tan, exp, ln, sqrt, sinh, cosh, tanh, asin, acos, atan; "2 m l" means 2·m·l. Greek names such as theta and phi are shown as θ and φ.

Equations of motion

Try it with numbers

The equations above are solved for the accelerations at every step and integrated with fourth-order Runge-Kutta in 4,000 steps. When nothing depends on t, the energy function h = Σ q′ ∂L/∂q′ − L must stay constant; its drift is a check on the numbers. For study and planning, not a substitute for professional judgement.

Download

What it does

Lagrangian mechanics turns a mechanics problem into bookkeeping: write down the kinetic energy T and the potential energy V in whatever coordinates suit the system (angles, distances along a slope, a radius), form L = T − V, and the equations of motion follow from the Euler-Lagrange equations, one per coordinate:

d/dt (∂L/∂q′) − ∂L/∂q = 0.

The differentiation is mechanical but error-prone by hand, especially the total time derivative, which needs the chain rule through every coordinate and rate. This helper does it symbolically. It shows the Lagrangian, each generalised momentum ∂L/∂q′, each ∂L/∂q and d/dt(∂L/∂q′), and the equation of motion. For one coordinate it solves for the acceleration; for several it gives the mass-matrix form M(q) q″ = F. It also gives the energy function h and says whether it is conserved (it is when L has no explicit time in it).

A plain-text copy of everything is ready to paste into SymPy, a notebook or your notes, and a numerical run integrates the equations from any start so you can see the motion and check that energy is conserved.

How to use it

  1. Pick a preset or choose Custom.
  2. List the coordinates, separated by commas (theta, or x, theta).
  3. Type T and V. Write a rate with a dash: theta’ (or thetadot). Every other name is a constant; t is time. Juxtaposition multiplies (“1/2 m l^2 theta’^2”).
  4. Read the equations. Greek names show as letters. A rate is shown with a prime (θ′ for dθ/dt, θ″ for d²θ/dt², th₁′ for th1), except x, y and w, which get the usual dots (ẋ, ẍ).
  5. Under Try it with numbers, give each constant a value, the starting value and rate of each coordinate, and a run time. The chart shows each coordinate against time; download the run as CSV.

Worked example

For the simple pendulum, T = ½ m l² θ′² and V = −m g l cos θ. The page gives the momentum l²·m·θ′, the equation l²·m·θ″ + g·l·m·sin(θ) = 0, solved as θ″ = −g·sin(θ)/l, and the energy function l²·m·θ′²/2 − g·l·m·cos(θ), which is conserved. With m = 1, g = 9.81, l = 1 and a start at θ = 1 rad at rest, after 10 s the pendulum is at θ = −0.46325 with rate 2.6365, and the energy function is kept to about 1.4 × 10⁻¹¹. The pendulum on a sliding cart gives the coupled pair (M + m)ẍ + l·m·cos(θ)·θ″ − l·m·sin(θ)·θ′² = 0 and l·m·cos(θ)·ẍ + l²·m·θ″ + g·l·m·sin(θ) = 0 (shown term by term), with mass matrix [M + m, l·m·cos(θ); l·m·cos(θ), l²·m].

Tips

  • Build T from the velocity of each mass: for a mass at (x, y), T = ½ m (ẋ² + ẏ²). For example a pendulum bob at (l sin θ, −l cos θ) gives ½ m l² θ′² after sin² + cos² = 1, which the helper simplifies for you.
  • A coordinate that does not appear in L (only its rate does) is cyclic: its momentum is conserved.
  • If a run’s energy drift is large, shorten the run or reduce violent starting values; the RK4 step is the run time ÷ 4,000.

FAQ

Can it handle forces that are not from a potential (friction, driving)? Not directly. Time-dependent potentials and moving constraints are fine (see the shaken pivot), but friction needs generalised forces added by hand.

Why are some terms not combined? The simplifier expands products and combines like terms, and knows sin² + cos² = 1, but it is not a full computer algebra system. The equations are correct even when a tidier form exists. It is for study and planning, not a substitute for professional judgement.

Which functions can I use? sin, cos, tan, exp, ln, log, sqrt, sinh, cosh, tanh, asin, acos and atan, and whole or fractional number powers.

Where the numbers come from

  • Lagrangian mechanics: L = T − V, the Euler-Lagrange equations d/dt(∂L/∂q′) − ∂L/∂q = 0, generalised momenta and the energy function h = Σ q′ ∂L/∂q′ − L. Standard results in any classical mechanics text.
  • The symbolic differentiator, simplifier and Runge-Kutta integrator are written for this site in TypeScript (no outside algebra system).
  • Checked against SymPy's euler_equations for six systems (simple, cart, double, spring and shaken-pivot pendulums and a bead on a spinning hoop), evaluated at a test point, and against a SciPy solve_ivp run of the double pendulum.
  • The preset parameter values are made up.

Standard scientific values, such as constants, atomic weights and melting points, are facts found in every textbook; we name where ours were checked. If you are an author or publisher and want a value, a credit or a table changed or removed, tell us and we will act quickly.

Last updated 2026-11-09.

Related tools

Pendulum lab analyser #902 Paste your pendulum lengths and periods (or times for 10 swings) and get g with its uncertainty from a straight-line fit of T² against L, the exact correction for large swings, an optional unknown-length offset, residuals, and how far the small-angle formula is off at any amplitude. Two-body orbit sandbox #903 Give two bodies a mass, a starting position and a velocity and watch them orbit their centre of mass. Get the shape, eccentricity, semi-major axis, closest and farthest approach and period, with an independent numerical check that energy and angular momentum are conserved. Moment of inertia builder #904 Build a body from simple uniform parts (rod, disc or cylinder, tube, ring, sphere, shell, box, point mass, and holes), place each one relative to the axis, and get the total moment of inertia with every step shown, the radius of gyration, the centre of mass, the moment about it and the spin energy at any rpm. Coupled oscillators and normal modes #907 Line up to 12 masses joined by springs, between walls or floating free, and get every normal mode: its frequency, period and shape. Watch a single mode or any starting push move, see how the energy is shared between the modes, and download the motion. Uncertainty propagation calculator #25 Type your formula and your measurements with their uncertainties, or paste repeated readings. Get the result with its uncertainty, which input matters most, and a Monte Carlo check. Projectile and drag simulator #901 Launch a ball at any speed, angle and height and see its real path through the air: quadratic drag from its size, mass and drag coefficient, a head- or tailwind, the range, highest point, time of flight, landing speed, the best angle for distance and how much the air costs compared with a vacuum.