What a Differential Equation Is
A differential equation is an equation whose unknown is a whole function, and which ties that function to its own derivatives. Instead of asking "which number makes this true?", it asks "which function changes in exactly this way?". This lesson covers the vocabulary (order, linear, initial value problem), what counts as a solution, and how to check one with SymPy.
The idea
Most laws of change are easier to state as a rate than as a formula. "The population grows by 3% of its current size per year" is a statement about the derivative:
The unknown is the function . A solution is any function that makes the equation true for every . Here works for any constant , because its derivative is . (See derivatives of exponentials.)
So a differential equation usually has a whole family of solutions, the general solution. Fixing one extra fact, such as , picks out one member, the particular solution . An equation plus that starting value is an initial value problem (IVP).
Vocabulary
| Term | Meaning | Example |
|---|---|---|
| ODE | Ordinary differential equation: one independent variable | |
| PDE | Partial differential equation: several variables, partial derivatives | (heat) |
| Order | Highest derivative that appears | is second order |
| Linear | and its derivatives appear only to the first power, not multiplied together | |
| Nonlinear | Anything else | , |
| Autonomous | The right side does not depend on directly | |
| Equilibrium | A constant solution, where | and for |
An -th order equation normally needs starting values: a position and a velocity for a second-order equation of motion.
Note: Solving a differential equation is a generalisation of finding an antiderivative. The equation is the simplest ODE, and its general solution is .
Checking a solution
Checking is always easier than solving: substitute the candidate and simplify. SymPy does that with checkodesol, and it can also solve many equations directly with dsolve.
import sympy as sp
t = sp.symbols("t")
C = sp.symbols("C")
y = sp.Function("y")
ode = sp.Eq(y(t).diff(t), y(t) - t) # y' = y - t
candidate = sp.Eq(y(t), t + 1 + C * sp.exp(t))
print("check:", sp.checkodesol(ode, candidate))
print("general:", sp.dsolve(ode))
print("y(0)=3 :", sp.dsolve(ode, ics={y(0): 3}))check: (True, 0)
general: Eq(y(t), C1*exp(t) + t + 1)
y(0)=3 : Eq(y(t), t + 2*exp(t) + 1)
(True, 0) means that after substitution the difference of the two sides simplified to 0. SymPy names its constants C1, C2, … and prints exp(t) for . With we get , so , which matches the last line.
Slope fields: seeing a solution without solving
A first-order equation tells you the slope at every point of the plane. Drawing short line segments with those slopes gives a slope field; solutions are the curves that follow the segments everywhere.
import numpy as np
import matplotlib.pyplot as plt
f = lambda t, y: y - t
T, Y = np.meshgrid(np.linspace(-2, 3, 21), np.linspace(-2, 4, 21))
S = f(T, Y)
L = np.sqrt(1 + S**2) # normalise the little arrows
plt.figure(figsize=(6, 4))
plt.quiver(T, Y, 1 / L, S / L, angles="xy", color="0.6", width=0.003)
ts = np.linspace(-2, 3, 200)
for C in [-1, -0.3, 0, 0.3]:
plt.plot(ts, ts + 1 + C * np.exp(ts), label=f"C = {C}")
plt.ylim(-2, 4)
plt.xlabel("t"); plt.ylabel("y"); plt.title("y' = y - t and four solutions")
plt.legend()
print("slope at (0, 1):", f(0, 1), " slope at (2, 0):", f(2, 0))slope at (0, 1): 1 slope at (2, 0): -2
The straight line () is special: the solutions above it run away upward, the ones below run away downward. Small changes in the starting value grow like , which is worth remembering when you later solve equations numerically.
In software
Differential equations are how programs describe anything that evolves:
| Where | Equation |
|---|---|
| Game physics | , integrated every frame (physics integration) |
| UI and camera smoothing | , the basis of frame-rate-independent damping |
| Springs in animation | (second-order equations) |
| Epidemics, populations | logistic and SIR models |
| Machine learning | gradient descent is a step-by-step solution of (gradient descent) |
The next lessons solve the main families by hand: separable, first-order linear and second-order linear equations. SciPy's numeric solver is covered in SciPy ODEs.
Exercises
Exercise 1: Classify
Give the order of each equation and say whether it is linear: (a) , (b) , (c) , (d) .
Answer
(a) first order, linear; (b) second order, linear; (c) first order, nonlinear; (d) third order, nonlinear.
Solution
Coefficients may depend on (like ) and the equation stays linear; only functions of itself break linearity.
Exercise 2: Pick the constant
The general solution of is . Find the particular solution with .
Answer
, so .
Solution
Exercise 3: Verify with SymPy
Check that solves , and find which starting values and it has.
Answer
It is a solution; and .
Solution
, so . At : , and gives 2.
import sympy as sp
t = sp.symbols("t")
y = sp.sin(2 * t) + 3 * sp.cos(2 * t)
print("y'' + 4y =", sp.simplify(y.diff(t, 2) + 4 * y))
print("y(0) =", y.subs(t, 0), " y'(0) =", y.diff(t).subs(t, 0))y'' + 4y = 0
y(0) = 3 y'(0) = 2
Test yourself
What is the order of ?
- First
- Second
- Third
- Fifth
Why does have infinitely many solutions?
- Because it is nonlinear
- Because every function solves it
- Because works for every constant until an initial value fixes
- It has only one solution
Which of these equations is linear?