Up to this point, we have focused on first-order differential equations. Any higher-order ordinary differential equation can be converted into a coupled system of first-order equations via reduction of order by introducing auxiliary state variables for the lower-order derivatives.
For example, consider a general second-order ODE:
Defining the auxiliary velocity variable transforms the single second-order equation into a system of two first-order equations:
which can be integrated directly using any vector Runge-Kutta or multistep solver!
import numpy as np
from scipy.integrate import solve_ivp
try:
import executable_engineering as exe
except ImportError:
%pip install -q executable_engineering
import executable_engineering as exeExample: Swinging Pendulum¶
The nonlinear equation of motion for a rigid pendulum of mass and length under gravity is:

Applying reduction of order, we define the two-component state vector :
Differentiating with respect to time gives the first-order vector ODE system:
def pendulum_rhs(t, y, g=9.81, l=1.0):
theta, theta_dot = y
return np.array([theta_dot, -(g / l) * np.sin(theta)])
y0 = [np.pi / 4.0, 0.0]
sol = solve_ivp(pendulum_rhs, (0.0, 10.0), y0, method="RK45", max_step=0.05)
exe.plot_pendulum_system(sol.t, sol.y[0], sol.y[1])