TExcelTAD
Home › Calculus Essentials › What a Differential Equation Is

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:

dPdt=0.03⋅P\frac{dP}{dt} = 0.03 \cdot P

The unknown is the function P(t)P(t). A solution is any function that makes the equation true for every tt. Here P(t)=Ce0.03tP(t) = Ce^{0.03t} works for any constant CC, because its derivative is 0.03⋅Ce0.03t=0.03⋅P(t)0.03 \cdot Ce^{0.03t} = 0.03 \cdot P(t). (See derivatives of exponentials.)

So a differential equation usually has a whole family of solutions, the general solution. Fixing one extra fact, such as P(0)=1000P(0) = 1000, picks out one member, the particular solution P(t)=1000e0.03tP(t) = 1000e^{0.03t}. An equation plus that starting value is an initial value problem (IVP).

Vocabulary

Term Meaning Example
ODE Ordinary differential equation: one independent variable y′=−2yy' = -2y
PDE Partial differential equation: several variables, partial derivatives ∂u/∂t=∂2u/∂x2\partial u/\partial t = \partial^2 u/\partial x^2 (heat)
Order Highest derivative that appears y′′+y=0y'' + y = 0 is second order
Linear yy and its derivatives appear only to the first power, not multiplied together y′+ty=sin⁡ty' + ty = \sin t
Nonlinear Anything else y′=y2y' = y^2, y′′+sin⁡y=0y'' + \sin y = 0
Autonomous The right side does not depend on tt directly y′=y(1−y)y' = y(1 - y)
Equilibrium A constant solution, where y′=0y' = 0 y=0y = 0 and y=1y = 1 for y′=y(1−y)y' = y(1 - y)

An nn-th order equation normally needs nn 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 y′=f(t)y' = f(t) is the simplest ODE, and its general solution is y=∫f(t) dt+Cy = \int f(t)\,dt + C.

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.

python · try it yourself
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 ete^t. With y(0)=3y(0) = 3 we get 0+1+C=30 + 1 + C = 3, so C=2C = 2, which matches the last line.

Slope fields: seeing a solution without solving

A first-order equation y′=f(t,y)y' = f(t, y) 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.

python · try it yourself
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 y=t+1y = t + 1 (C=0C = 0) is special: the solutions above it run away upward, the ones below run away downward. Small changes in the starting value grow like ete^t, 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 x′′=F/mx'' = F/m, integrated every frame (physics integration)
UI and camera smoothing x′=−k(x−target)x' = -k(x - \text{target}), the basis of frame-rate-independent damping
Springs in animation mx′′+cx′+kx=0mx'' + cx' + kx = 0 (second-order equations)
Epidemics, populations logistic and SIR models
Machine learning gradient descent is a step-by-step solution of θ′=−∇L(θ)\theta' = -\nabla L(\theta) (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) y′=4y−1y' = 4y - 1, (b) y′′+3y′=etyy'' + 3y' = e^t y, (c) y′=cos⁡(y)y' = \cos(y), (d) y′′′+(y′)2=0y''' + (y')^2 = 0.

Answer

(a) first order, linear; (b) second order, linear; (c) first order, nonlinear; (d) third order, nonlinear.

Solution
(a) highest derivative y′→order 1; y appears to the first power→linear(b) highest derivative y′′→order 2; ety is a coefficient times y→linear(c) cos⁡(y) is not of the form a(t) y+b(t)→nonlinear(d) highest derivative y′′′→order 3; (y′)2 squares a derivative→nonlinear\begin{aligned} &\text{(a) highest derivative } y' &&\to \text{order 1; } y \text{ appears to the first power} &&\to \text{linear} \\ &\text{(b) highest derivative } y'' &&\to \text{order 2; } e^t y \text{ is a coefficient times } y &&\to \text{linear} \\ &\text{(c) } \cos(y) \text{ is not of the form } a(t)\,y + b(t) && &&\to \text{nonlinear} \\ &\text{(d) highest derivative } y''' &&\to \text{order 3; } (y')^2 \text{ squares a derivative} &&\to \text{nonlinear} \end{aligned}

Coefficients may depend on tt (like ete^t) and the equation stays linear; only functions of yy itself break linearity.

Exercise 2: Pick the constant

The general solution of y′=−y/2y' = -y/2 is y=Ce−t/2y = Ce^{-t/2}. Find the particular solution with y(2)=6y(2) = 6.

Answer

y=6e⋅e−t/2=6e1−t/2y = 6e \cdot e^{-t/2} = 6e^{1 - t/2}, so C=6e≈16.31C = 6e \approx 16.31.

Solution
y(2)=Ce−1=6⇒C=6e≈16.31y(t)=6e⋅e−t/2=6e1−t/2check: y′=−12⋅6e1−t/2=−y/2 ✓,y(2)=6e0=6 ✓\begin{aligned} y(2) &= Ce^{-1} = 6 \quad\Rightarrow\quad C = 6e \approx 16.31 \\ y(t) &= 6e \cdot e^{-t/2} = 6e^{1 - t/2} \\ \text{check: } y' &= -\tfrac{1}{2} \cdot 6e^{1 - t/2} = -y/2 \ \checkmark, \qquad y(2) = 6e^0 = 6 \ \checkmark \end{aligned}

Exercise 3: Verify with SymPy

Check that y=sin⁡(2t)+3cos⁡(2t)y = \sin(2t) + 3\cos(2t) solves y′′+4y=0y'' + 4y = 0, and find which starting values y(0)y(0) and y′(0)y'(0) it has.

Answer

It is a solution; y(0)=3y(0) = 3 and y′(0)=2y'(0) = 2.

Solution

y′′=−4sin⁡(2t)−12cos⁡(2t)=−4yy'' = -4\sin(2t) - 12\cos(2t) = -4y, so y′′+4y=0y'' + 4y = 0. At t=0t = 0: y=0+3=3y = 0 + 3 = 3, and y′=2cos⁡(2t)−6sin⁡(2t)y' = 2\cos(2t) - 6\sin(2t) gives 2.

python · try it yourself
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 y′′−5y′+y3=ty'' - 5y' + y^3 = t?

  1. First
  2. Second
  3. Third
  4. Fifth

Why does y′=2yy' = 2y have infinitely many solutions?

  1. Because it is nonlinear
  2. Because every function solves it
  3. Because y=Ce2ty = Ce^{2t} works for every constant CC until an initial value fixes CC
  4. It has only one solution

Which of these equations is linear?

  1. y′=y2y' = y^2
  2. y′+t2y=sin⁡ty' + t^2 y = \sin t
  3. y′′+sin⁡y=0y'' + \sin y = 0
  4. y′y=1y' y = 1