Differential Equations Intro
A differential equation relates an unknown function to its derivatives. Newton's second law, the cooling of a cup of coffee, the charge on a capacitor, the spread of an infection and the temperature along a metal rod are all described this way: you know how a quantity changes, and you want to know the quantity itself. This course teaches you to solve such equations exactly when that is possible, to understand their solutions qualitatively when it is not, and to compute them numerically in Python.
The reference book
The topic order of this course follows Notes on Diffy Qs: Differential Equations for Engineers by Jiří Lebl, a free open textbook released under the Creative Commons Attribution-ShareAlike licence (CC BY-SA). It is available at jirka.org/diffyqs. Thanks to the author for making it openly available.
The book is used only as a map of topics. All explanations, examples, code and exercises in these lessons are written from scratch for this site.
What is in the course
| Part | Topics |
|---|---|
| 1. First-order equations | integrals as solutions, slope fields, separable and linear equations, substitutions, autonomous equations, Euler's method, exact equations, existence and uniqueness, models |
| 2. Higher-order linear equations | the characteristic equation, real, complex and repeated roots, vibrations, undetermined coefficients, variation of parameters, resonance, RLC circuits |
| 3. Systems | matrix form, the eigenvalue method, phase portraits, the matrix exponential, coupled oscillators |
| 4. The Laplace transform | transforms and inverses, solving initial value problems, step functions, convolution, the delta function, transfer functions |
| 5. Power series | series solutions, the Frobenius method, Bessel and Legendre functions |
| 6. Fourier series and PDEs | eigenvalue problems, Fourier series, the heat, wave and Laplace equations |
| 7. Nonlinear systems | linearization, stability, the pendulum, predator and prey, limit cycles, chaos |
| 8. In practice | population and epidemic models, where software solves differential equations |
Vocabulary in one example
Take the equation
- It is an ordinary differential equation (ODE): one independent variable . An equation with partial derivatives in several variables is a partial differential equation (PDE).
- Its order is 1, the highest derivative that appears.
- It is linear: and appear only to the first power, not multiplied together.
- Together with the initial condition it is an initial value problem (IVP).
- A solution is a function that makes the equation true. Here : its derivative is , and .
You can check a claimed solution by substituting it, and SymPy can do both the solving and the checking:
import sympy as sp
t = sp.symbols("t")
y = sp.Function("y")
ode = sp.Eq(y(t).diff(t), -sp.Rational(1, 2) * y(t))
sol = sp.dsolve(ode, ics={y(0): 8})
print(sol)
print("check:", sp.checkodesol(ode, sol))Eq(y(t), 8*exp(-t/2))
check: (True, 0)
When no formula exists, a numerical solver follows the slope step by step. SciPy's solve_ivp gives the same numbers:
import numpy as np
from scipy.integrate import solve_ivp
sol = solve_ivp(lambda t, y: -0.5 * y, (0, 4), [8.0], t_eval=[0, 1, 2, 3, 4], rtol=1e-10, atol=1e-12)
for t, y in zip(sol.t, sol.y[0]):
print(f"t = {t:.0f}: numeric {y:.6f}, exact {8 * np.exp(-0.5 * t):.6f}")t = 0: numeric 8.000000, exact 8.000000
t = 1: numeric 4.852245, exact 4.852245
t = 2: numeric 2.943036, exact 2.943036
t = 3: numeric 1.785041, exact 1.785041
t = 4: numeric 1.082682, exact 1.082682
What you should know first
- Derivatives, integrals, the chain rule, partial fractions and Taylor series: Calculus Essentials and Calculus in Depth. Their ODE chapters (Introduction to Differential Equations, Modeling with Differential Equations) are a gentle preview of this course.
- Matrices, eigenvalues and eigenvectors for the systems part: Linear Algebra & Matrix Theory.
- Arrays in NumPy. How the numerical solvers themselves work is the subject of Numerical Methods.
How lessons work
Each lesson explains one method, writes the formulas in math notation, solves examples with SymPy (exact) and NumPy/SciPy (numerical), and ends with an In software note, exercises with answers and worked solutions, and a short quiz. Every example runs in your browser.
Tip: Always check a solution by substituting it back into the equation. It takes a minute by hand and one line with
sp.checkodesol, and it catches almost every algebra slip.
Learning paths
| Your goal | Suggested route |
|---|---|
| School to university math | Calculus in Depth → Linear Algebra → this course |
| Engineering and physics | parts 1, 2, 3, 4 and 6 of this course |
| Simulation, games and scientific computing | parts 1 and 3 → Numerical Methods → Game Physics |
| Data science and modelling | parts 1, 7 and 8 (population and epidemic models) |
Exercises
Exercise 1: Classify
State the order of each equation and whether it is linear: (a) ; (b) ; (c) .
Answer
(a) order 2, linear ODE; (b) order 1, nonlinear ODE; (c) a linear PDE, second order in and first order in (order 2 overall).
Solution
In (a) the unknown and its derivatives appear to the first power with coefficients that depend only on , so it is linear; is a forcing term. In (b) the term makes it nonlinear. In (c) the unknown depends on two variables and the equation contains partial derivatives, so it is a PDE (the heat equation); the highest derivative, , has order 2.
Exercise 2: Check a solution by hand
Show that solves , and find the other exponential that solves it.
Answer
also solves it.
Solution
Substituting gives , so . For : . The other root is , giving . This is the characteristic equation of Constant Coefficients: Real Roots.
Exercise 3: Half-life (code)
For , when does reach half its starting value? Confirm with SymPy.
Answer
At .
Solution
gives , so (SymPy prints the second form).
import sympy as sp
t = sp.symbols("t", positive=True)
T = sp.solve(sp.Eq(8 * sp.exp(-t / 2), 4), t)[0]
print(T, float(T))log(4) 1.3862943611198906
Test yourself
What is the order of ?
- 1
- 2
- 3
- It has no order
Which equation is a partial differential equation?
An initial value problem is…
- a differential equation together with the value of the solution at one starting point
- an equation with no derivatives
- a list of numerical values
- a differential equation with no solution