TExcelTAD
Home › Differential Equations › Differential Equations Intro

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

dydt=−0.5 y,y(0)=8.\frac{dy}{dt} = -0.5\,y, \qquad y(0) = 8.
  • It is an ordinary differential equation (ODE): one independent variable tt. 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: yy and y′y' appear only to the first power, not multiplied together.
  • Together with the initial condition y(0)=8y(0) = 8 it is an initial value problem (IVP).
  • A solution is a function that makes the equation true. Here y(t)=8e−0.5ty(t) = 8e^{-0.5t}: its derivative is −4e−0.5t=−0.5 y-4e^{-0.5t} = -0.5\,y, and y(0)=8y(0) = 8.

You can check a claimed solution by substituting it, and SymPy can do both the solving and the checking:

python · try it yourself
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:

python · try it yourself
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

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) y′′+3y′+2y=sin⁡ty'' + 3y' + 2y = \sin t; (b) y′=y2−ty' = y^2 - t; (c) ut=4uxxu_t = 4u_{xx}.

Answer

(a) order 2, linear ODE; (b) order 1, nonlinear ODE; (c) a linear PDE, second order in xx and first order in tt (order 2 overall).

Solution

In (a) the unknown and its derivatives appear to the first power with coefficients that depend only on tt, so it is linear; sin⁡t\sin t is a forcing term. In (b) the term y2y^2 makes it nonlinear. In (c) the unknown u(x,t)u(x, t) depends on two variables and the equation contains partial derivatives, so it is a PDE (the heat equation); the highest derivative, uxxu_{xx}, has order 2.

Exercise 2: Check a solution by hand

Show that y=e2ty = e^{2t} solves y′′−y′−2y=0y'' - y' - 2y = 0, and find the other exponential erte^{rt} that solves it.

Answer

y=e−ty = e^{-t} also solves it.

Solution

Substituting y=erty = e^{rt} gives (r2−r−2)ert=0(r^2 - r - 2)e^{rt} = 0, so r2−r−2=(r−2)(r+1)=0r^2 - r - 2 = (r - 2)(r + 1) = 0. For r=2r = 2: 4e2t−2e2t−2e2t=04e^{2t} - 2e^{2t} - 2e^{2t} = 0. The other root is r=−1r = -1, giving e−te^{-t}. This is the characteristic equation of Constant Coefficients: Real Roots.

Exercise 3: Half-life (code)

For y′=−0.5yy' = -0.5y, when does yy reach half its starting value? Confirm with SymPy.

Answer

At t=2ln⁡2≈1.386t = 2\ln 2 \approx 1.386.

Solution

y=y0e−0.5t=y0/2y = y_0 e^{-0.5t} = y_0/2 gives e−0.5t=1/2e^{-0.5t} = 1/2, so t=2ln⁡2=ln⁡4t = 2\ln 2 = \ln 4 (SymPy prints the second form).

python · try it yourself
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 y′′′+t y′=ety''' + t\,y' = e^t?

  1. 1
  2. 2
  3. 3
  4. It has no order

Which equation is a partial differential equation?

  1. y′=tyy' = ty
  2. y′′+y=0y'' + y = 0
  3. ut=uxxu_t = u_{xx}
  4. x2+y2=1x^2 + y^2 = 1

An initial value problem is…

  1. a differential equation together with the value of the solution at one starting point
  2. an equation with no derivatives
  3. a list of numerical values
  4. a differential equation with no solution