Tools › Numerical Methods › Equation Solvers › ODE and Nonlinear Equation Solver › Example

Damped pendulum released at 172°: classical RK4 with the four slopes of the first step and a step-halving error estimate

ToolODE and Nonlinear Equation Solver
SourceOriginal case (illustrative: a 1 m pendulum with g = 9.81 m/s² and a damping rate of 0.3 per second, released from rest 3 rad from the bottom), checked against scipy.integrate.solve_ivp (DOP853, rtol 1e-12) in test_ode_nonlinear_solver.php.
LevelUndergraduate

Problem

A pendulum obeys θ″ + c θ′ + (g/L) sin θ = 0 with g = 9.81 m/s², L = 1 m and c = 0.3 1/s. It is released from rest at θ = 3 rad. Write the equation as two first-order equations and integrate to t = 15 s with the classical fourth-order Runge-Kutta method and 1,500 steps; show the first step and estimate the error.

Inputs to Enter

  • theta' = omega and omega' = -c*omega - (g/L)*sin(theta), with g = 9.81, L = 1, c = 0.3
  • Initial values theta = 3, omega = 0; start time 0, end time 15
  • Method: classical Runge-Kutta (RK4), 1,500 steps (h = 0.01)
Open the ODE and Nonlinear Equation Solver tool

Answers

  • k₁ = (0, −1.3844) at (3, 0); k₂ = (−0.0069219, −1.3823); k₃ = (−0.0069116, −1.3826); k₄ = (−0.013826, −1.3809)
  • After the first step: θ = 3 + (0.01/6)(0 + 2(−0.0069219) + 2(−0.0069116) − 0.013826) = 2.9999308, ω = −0.013825365
  • At t = 15: θ = −0.191392 rad, ω = 0.539828 rad/s (DOP853 reference −0.19139211, 0.53982777)
  • Step halving: θ changes from −0.1913921721 to −0.1913921107, so the error estimate is 6.1 × 10⁻⁸ × 16/15 = 6.55 × 10⁻⁸ (true error 6.6 × 10⁻⁸)

Notes

Open this case in the tool: /analysis-tools/numerical-methods/equation-solvers/ode-nonlinear-solver/?try=damped-pendulum. The angle is in radians throughout; the small-angle formula does not apply at 172°: the first half swing takes 1.99 s against π√(L/g) = 1.00 s. With Euler and the same 1,500 steps the step-halving estimate for θ is 0.24 and the tool warns that the answer has not converged.

More Examples for This Tool