Integrals as Solutions
The simplest differential equation has a right-hand side that does not involve the unknown at all:
Solving it is integration. Every equation in this course generalises this case, so it is worth getting the details right: the constant of integration, how an initial condition fixes it, and what to do when has no elementary antiderivative.
The general and the particular solution
By the Fundamental Theorem of Calculus, every solution of has the form
The constant is free: the graphs of all solutions are vertical shifts of each other. An initial condition picks one of them, and the cleanest way to write it uses a definite integral:
At the integral is zero, so automatically. The variable is a dummy variable, renamed so it does not clash with the upper limit .
Example. , . Then , and gives , so .
import sympy as sp
x = sp.symbols("x")
y = sp.Function("y")
print(sp.dsolve(sp.Eq(y(x).diff(x), 3 * x**2 + 2), ics={y(1): 5}))Eq(y(x), x**3 + 2*x + 2)
Second derivatives: motion under constant acceleration
If (constant acceleration), integrate twice. Each integration brings a constant, and the initial position and velocity fix them:
A ball thrown upward at m/s from a height of 2 m, with m/s, reaches its highest point when , at s.
import sympy as sp
t = sp.symbols("t")
x = sp.Function("x")
sol = sp.dsolve(sp.Eq(x(t).diff(t, 2), sp.Rational(-49, 5)),
ics={x(0): 2, x(t).diff(t).subs(t, 0): 15}).rhs
print("x(t) =", sp.expand(sol))
t_top = sp.solve(sol.diff(t), t)[0]
print("top at t =", t_top, "=", round(float(t_top), 3), "s, height", round(float(sol.subs(t, t_top)), 3), "m")x(t) = -49*t**2/10 + 15*t + 2
top at t = 75/49 = 1.531 s, height 13.48 m
When there is no formula
Some integrals have no antiderivative in elementary functions, for example . The solution still exists and is perfectly well defined by the definite integral. You can name it (here ) or compute it numerically:
import math
from scipy.integrate import quad
for xv in (0.5, 1.0, 2.0):
value, err = quad(lambda s: math.exp(-s * s), 0, xv)
print(f"y({xv}) = {value:.8f} via erf: {math.sqrt(math.pi) / 2 * math.erf(xv):.8f}")y(0.5) = 0.46128101 via erf: 0.46128101
y(1.0) = 0.74682413 via erf: 0.74682413
y(2.0) = 0.88208139 via erf: 0.88208139
This is the first appearance of the idea behind every numerical ODE solver: if you cannot integrate exactly, add up small pieces of the slope.
In software
- Dead reckoning in navigation and the position update in a game loop integrate velocity to get position:
pos += vel * dtis a one-step approximation of . - Special functions such as
math.erf,scipy.special.fresnelandscipy.special.expiexist precisely because these integrals come up so often that libraries tabulate them.
Exercises
Exercise 1: Fix the constant
Solve , .
Answer
.
Solution
and , so .
Exercise 2: Braking distance
A car moving at 30 m/s brakes with constant deceleration 6 m/s. How long does it take to stop, and how far does it travel?
Answer
5 s and 75 m.
Solution
at . Then m.
Exercise 3: A definite-integral solution (code)
Solve , , and compute numerically.
Answer
.
Solution
, the sine integral .
import numpy as np
from scipy.integrate import quad
from scipy.special import sici
value, _ = quad(lambda s: np.sinc(s / np.pi), 0, np.pi) # np.sinc(u) = sin(pi u)/(pi u)
print(f"{value:.6f} {sici(np.pi)[0]:.6f}")1.851937 1.851937
Test yourself
The general solution of is…
Why is convenient?
- It avoids derivatives
- It satisfies automatically and works even without an antiderivative formula
- It is always a polynomial
- It removes the need for
How many initial conditions does need for a unique solution?
- None
- One
- Two
- Three