Damped pendulum calculator

Solve the full pendulum equation, θ'' + (b/m)θ' + (g/L) sin θ = 0, for any length, mass, damping and launch, and watch it swing. You get the angle against time next to the small-angle model, the phase portrait, the peak and period, the energy left and the speed that sends it over the top. It opens on the simple pendulum challenge of Skill-Lync's MATLAB and Python courses. The second tab checks the numbers your ode45 or odeint code printed. Free, no sign-up, runs in your browser.

RK4 with 1 ms steps · checked against scipy DOP853 at 10⁻¹³ · Updated 20 Nov 2026

b is the coefficient in the equation above, so b/m is in 1/s. θ(0) is in degrees here; the ODE itself, and every solver, works in radians. Up to 200 s.

First peak56.43°at t = 0.531 s
Period, first swing2.1313 s2π√(L/g) = 2.0061 s
θ at t = 20 s-0.3032 rad-17.37° · θ' -1.5679 rad/s
Pendulum angle against time: the nonlinear ODE and the small-angle model-50°-25°0°25°50°05101520sin θ (exact ODE)small-angle modelt (s)
Phase portrait: angular velocity against angle-202-50°-25°0°25°50°θ (degrees)startθ' (rad/s)
  • Damping ratio ζ = 0.00798 (lightly damped); 37.3% of the starting energy is left at 20 s.
  • The exact undamped period for a 56.4° swing is 2.1349 s, 6.4% over 2π√(L/g).
  • From θ(0) = 0.0°, over the top within 20 s needs θ'(0) above 6.364 rad/s.
  • ode45 / RK45 at the default tolerances (1e-3, 1e-6): θ = -0.3349 rad at 20 s, 3.2e-2 rad off.
  • Small-angle model at 20 s: θ = -0.1109 rad.

What is the simple pendulum ODE challenge?

A pendulum of length L = 1 m with a 1 kg bob hangs straight down. At t = 0 it is kicked to 3 rad/s. Air and pivot friction act as a damping term with b = 0.05, and you simulate 0 to 20 s, plot the angle and angular velocity, and animate the swing. It is the ODE challenge of Skill-Lync's MATLAB for Mechanical Engineers (the Vibrations and Dynamics week) and Python for Mechanical Engineers courses, and 897 public student reports have "pendulum" in their title. The equation of motion:

ode45 and odeint only take first-order equations, so you split the second-order ODE into two: the angle and the angular velocity. This state vector is what your ODE function returns:

The calculator solves exactly this with fixed 1 ms Runge-Kutta steps, about 20,000 of them for the 20 s run, which takes a few milliseconds in a browser.

What are the right answers for the course pendulum?

For L = 1 m, m = 1 kg, b = 0.05, g = 9.81 m/s², θ(0) = 0 and θ'(0) = 3 rad/s: θ(20) = -0.3032 rad (-17.37°) and θ'(20) = -1.5679 rad/s. The first swing peaks at 56.43° after 0.531 s. There are 19 turning points in 20 s, the last at 34.73° (t = 19.31 s), and 37.3% of the starting 4.5 J of energy is left at the end. Solved by Skill-Lync with scipy's DOP853 at a relative tolerance of 10⁻¹³ and checked with a second, implicit solver (Radau):

t (s)θ (rad)θ (degrees)θ' (rad/s)
0003
50.69221439.661-1.612827
10-0.768940-44.057-0.069329
150.56130732.1611.131387
20-0.303245-17.375-1.567887

The swing dies away slowly. The damping ratio is tiny:

ζ = 0.00798, so each turning point is only about 2.7% lower than the one before (on average over the 19 in 20 s). Left alone, this pendulum would still keep about 22% of its swing after a minute.

Why is the period 2.131 s and not 2π√(L/g)?

Because 2π√(L/g) = 2.0061 s is the period of the small-angle model, where sin θ is replaced by θ. That is only right for small swings. A pendulum that swings to 57.2° (where the course pendulum would go without damping) takes 2.1388 s, which is 6.6% longer:

K is the complete elliptic integral of the first kind; the AGM form (arithmetic-geometric mean) is the quick way to compute it. The damped course pendulum's first full swing takes 2.1313 s (6.2% over 2π√(L/g)). Later swings are smaller and faster: the last full swing in 20 s takes 2.0545 s.

So the small-angle model runs fast: in 20 s it completes 9.97 swings against the real 9.5, and at the end it gives θ = -0.1109 rad instead of -0.3032. Keep "Show the small-angle model" ticked in the calculator to watch the two curves part. At 10° amplitude the period error is 0.19%, and the model is fine.

How accurate is ode45 at its default tolerances?

Less accurate than most reports assume. ode45 uses the Dormand-Prince 5(4) pair with a relative tolerance of 10⁻³ and an absolute tolerance of 10⁻⁶ unless you pass odeset options. scipy's RK45 uses the same pair and the same defaults. Skill-Lync ran it on the course pendulum, and the calculator's RK45 is a step-for-step port that reproduces scipy's results to 10⁻¹⁴:

RelTol / AbsTolθ(20) (rad)Error at 20 sWorst error, 0-20 sFunction calls
1e-3 / 1e-6 (default)-0.3349040.0317 rad (1.81°)0.0440 rad458
1e-6 / 1e-9-0.3032551.0 × 10⁻⁵ rad1.6 × 10⁻⁵ rad2,198
1e-8 / 1e-10-0.3032458.7 × 10⁻⁸ rad1.5 × 10⁻⁷ rad4,646
exact-0.303245–––

At the defaults the answer at 20 s is off by 0.032 rad (1.8°), and the worst point along the way is 0.044 rad (2.5°) off. The plot looks right, which is why nobody notices. None of the 30 ode45 reports in a sample of 45 sets RelTol or AbsTol. Tightening to 10⁻⁸ / 10⁻¹⁰ costs 10 times the function calls, a few milliseconds here, and the error drops to 8.7 × 10⁻⁸ rad. MATLAB's step-size control differs from scipy's in detail, so its default-tolerance digits will differ too; expect an error of this size, not these exact digits.

Two things that do not fix it. A longer tspan such as linspace(0, 20, 500) only says where you want output; the solver still picks its own steps and interpolates between them. And Python's odeint is not affected: its defaults are about 1.5 × 10⁻⁸, and on this problem it stays within 2.3 × 10⁻⁷ rad.

Accurate code for both, with the animation in MATLAB:

L = 1; m = 1; b = 0.05; g = 9.81;
f = @(t, y) [y(2); -(b/m)*y(2) - (g/L)*sin(y(1))];
opts = odeset('RelTol', 1e-8, 'AbsTol', 1e-10);   % the defaults are 1e-3 and 1e-6
[t, y] = ode45(f, linspace(0, 20, 500), [0; 3], opts);
for k = 1:numel(t)
    x = L*sin(y(k,1));  z = -L*cos(y(k,1));        % radians: sin, not sind
    plot([0 x], [0 z], 'k-', x, z, 'o', 'MarkerSize', 12, 'MarkerFaceColor', 'b');
    axis([-1.2 1.2 -1.2 1.2]); axis square; drawnow;
end
import numpy as np
from scipy.integrate import solve_ivp

L, m, b, g = 1.0, 1.0, 0.05, 9.81

def pendulum(t, y):
    theta, omega = y
    return [omega, -(b / m) * omega - (g / L) * np.sin(theta)]

t = np.linspace(0, 20, 500)
sol = solve_ivp(pendulum, (0, 20), [0, 3], t_eval=t, rtol=1e-8, atol=1e-10)
print(sol.y[0][-1])   # theta at t = 20 s, rad

The Python version prints -0.3032452, which Skill-Lync ran as printed.

How fast must it be launched to go over the top?

To reach the top, the kinetic energy at the bottom must cover the 2mgL height gain:

For L = 1 m that is 6.264 rad/s without damping. With b = 0.05 the pendulum loses energy on the way up and needs 6.364 rad/s. Same pendulum, different launch speeds:

θ'(0) (rad/s)First peakSmall-angle model's peakFirst full swingUndamped exact period
118.1°18.1°2.018 s2.019 s
236.8°36.1°2.058 s2.060 s
3 (course)56.4°54.2°2.131 s2.139 s
478.1°72.3°2.259 s2.277 s
5103.9°90.3°2.495 s2.544 s
6141.4°108.4°3.124 s3.408 s
6.3163.9°113.8°3.869 sover the top
6.4Goes over the top and keeps spinning: 1.0 full turns by 20 s
7Goes over the top and keeps spinning: 3.2 full turns by 20 s

Near the critical speed the swing slows right down at the top: at 6.3 rad/s the first swing takes 3.87 s, nearly twice 2π√(L/g). The small-angle model knows none of this: its peak simply grows in proportion to the launch speed, and it always swings back.

Which mistakes show up in published reports?

Skill-Lync read 45 random public reports of the challenge on 20 Nov 2026; 23 show their full code. 30 solve with ode45, 28 use b = 0.05, 26 start from [0; 3] and 15 use linspace(0, 20, 500). What we found, and what the Check tab catches:

  • Default tolerances, never changed. 0 of 30 ode45 reports set RelTol or AbsTol, so their θ(20) carries the default-tolerance error shown above, a few hundredths of a radian.
  • sind and cosd on a radian angle. One report draws the bob at x = −L·sind(θ), y = −L·cosd(θ) with θ from ode45 in radians. A 56° swing is drawn as a 1° wobble. The same mistake inside the ODE function, sind(θ), makes gravity 57 times too weak.
  • Swapped initial conditions. [3; 0] instead of [0; 3] starts the pendulum at 172° with no speed: a completely different motion. The order must match the state vector [θ; θ'].
  • Plotting the small-angle model as the answer. Fine at 10°, wrong by -0.19 rad at 20 s here.
  • Also recognised: g/L written as L/g, +(b/m)θ' (the swing grows instead of dying), cos θ for sin θ, and b left at 0.

What this calculator does not cover

  • Compound (physical) pendulums. A rod or a large bob has its own moment of inertia; the equation becomes I θ'' + c θ' + m g d sin θ = 0. You can still use the calculator: set L to the equivalent length I/(m d) and b to m·c/I, where I is the moment of inertia about the pivot and d the pivot-to-centre-of-mass distance.
  • Driven and double pendulums, where the motion can become chaotic. Both need extra terms or a second degree of freedom.
  • Other damping laws. The model is linear viscous damping (proportional to θ'). Air drag on a real bob is closer to quadratic in speed, and pivot friction is closer to constant.
  • A string that goes slack. The rod is rigid. A bob on a string goes slack near the top unless it is launched at √(5g/L) or more (7.00 rad/s for L = 1 m), well above the rigid-rod speed.
Learn MATLAB and Python for engineering

The pendulum is one of the weekly challenges in Skill-Lync's MATLAB and Python courses for mechanical engineers, next to curve fitting, engine cycles and robotic-arm kinematics. Solving ODEs well is how vehicle dynamics, controls and CAE teams model anything that moves.

Frequently asked questions

What is the answer to the simple pendulum ODE challenge at t = 20 s?

With L = 1 m, m = 1 kg, b = 0.05, g = 9.81 m/s² and θ(0) = 0, θ'(0) = 3 rad/s: θ(20) = -0.3032 rad (-17.37°) and θ'(20) = -1.5679 rad/s. The first swing peaks at 56.43° after 0.531 s, and 37.3% of the starting energy is left at 20 s. Solved to 10⁻¹³ with scipy's DOP853 and checked with a second solver.

Why does my ode45 answer differ from the exact one?

Because ode45's default tolerances (RelTol 10⁻³, AbsTol 10⁻⁶) are loose for a 20 s run. The same Dormand-Prince solver at those settings (scipy RK45) ends 0.032 rad (1.8°) off at 20 s and up to 0.044 rad along the way. Set odeset('RelTol',1e-8,'AbsTol',1e-10) and the error falls below 10⁻⁶ rad. Asking for more output points with linspace does not change the accuracy.

What is the period of a pendulum with large amplitude?

Longer than 2π√(L/g). For L = 1 m that formula gives 2.0061 s, but a pendulum swinging to 57.2° takes 2.1388 s, 6.6% longer. The exact period is T₀ divided by the arithmetic-geometric mean of 1 and cos(θmax/2). At 10° the difference is 0.19%.

How fast must a pendulum be pushed to go over the top?

Without damping, starting from the bottom, the launch speed must exceed 2√(g/L), which is 6.264 rad/s for L = 1 m. With the course damping (b/m = 0.05 s⁻¹) it takes 6.364 rad/s. Below that the pendulum swings back; above it, it spins round the pivot.

What is the damping ratio of the course pendulum?

ζ = (b/m)/(2√(g/L)) = 0.00798, so it is very lightly damped: each turning point is about 2.7% lower than the one before, and over 20 s the peak falls from 56.4° to 34.7°.

Should I use odeint or solve_ivp in Python?

Either works if the tolerances are tight. odeint's defaults (about 1.5 × 10⁻⁸) already give θ within 2.3 × 10⁻⁷ rad over the 20 s run. solve_ivp defaults to RK45 with rtol 10⁻³ and atol 10⁻⁶, the same as ode45, so pass rtol=1e-8, atol=1e-10.

Related on Skill-Lync

Sources

  • J. R. Dormand, P. J. Prince, "A family of embedded Runge-Kutta formulae", Journal of Computational and Applied Mathematics 6 (1980) 19-26: the 5(4) pair inside ode45 and RK45.
  • MathWorks, ode45 and odeset documentation: default RelTol 10⁻³ and AbsTol 10⁻⁶; output at tspan points is interpolated, not stepped to.
  • SciPy 1.17, scipy.integrate.solve_ivp (RK45 defaults rtol 10⁻³, atol 10⁻⁶; DOP853; Radau) and odeint (defaults about 1.49 × 10⁻⁸).
  • C. G. Carvalhaes, P. Suppes, "Approximations for the period of the simple pendulum based on the arithmetic-geometric mean", American Journal of Physics 76 (2008) 1150: the exact period as T₀ / AGM(1, cos(θmax/2)).
  • Skill-Lync, sample of 45 public student reports of the pendulum challenge (23 with full code), read 20 Nov 2026: solvers, parameters, tolerances and animation code.
  • Skill-Lync, scripts/verify/pendulum.py: solves the course case with DOP853 at 10⁻¹³, cross-checks with Radau and the small-angle closed form, runs RK45 at three tolerance settings, odeint and the Python code on this page, and bisects the over-the-top speed. This page re-solves everything in the browser code and checks its numbers against that script at build time.
Free counselling

From a pendulum to an engineering career.

Turning equations of motion into working MATLAB and Python code is the skill simulation, vehicle dynamics and controls teams test for. A Skill-Lync counsellor can map the course that fits the role you want.

Talk to a course counsellor

Free. We call you back, usually the same day.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.