TExcelTAD
Home › Differential Equations › Integrals as Solutions

Integrals as Solutions

The simplest differential equation has a right-hand side that does not involve the unknown at all:

y′=f(x).y' = f(x).

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 ff has no elementary antiderivative.

The general and the particular solution

By the Fundamental Theorem of Calculus, every solution of y′=f(x)y' = f(x) has the form

y(x)=∫f(x) dx+C.y(x) = \int f(x)\,dx + C.

The constant CC is free: the graphs of all solutions are vertical shifts of each other. An initial condition y(x0)=y0y(x_0) = y_0 picks one of them, and the cleanest way to write it uses a definite integral:

y(x)=y0+∫x0xf(s) ds.y(x) = y_0 + \int_{x_0}^{x} f(s)\,ds.

At x=x0x = x_0 the integral is zero, so y(x0)=y0y(x_0) = y_0 automatically. The variable ss is a dummy variable, renamed so it does not clash with the upper limit xx.

Example. y′=3x2+2y' = 3x^2 + 2, y(1)=5y(1) = 5. Then y=x3+2x+Cy = x^3 + 2x + C, and 5=1+2+C5 = 1 + 2 + C gives C=2C = 2, so y=x3+2x+2y = x^3 + 2x + 2.

python · try it yourself
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 x′′(t)=ax''(t) = a (constant acceleration), integrate twice. Each integration brings a constant, and the initial position x0x_0 and velocity v0v_0 fix them:

x′(t)=v0+at,x(t)=x0+v0t+12at2.x'(t) = v_0 + at, \qquad x(t) = x_0 + v_0 t + \tfrac{1}{2}at^2.

A ball thrown upward at v0=15v_0 = 15 m/s from a height of 2 m, with a=−9.8a = -9.8 m/s2^2, reaches its highest point when x′(t)=0x'(t) = 0, at t=15/9.8≈1.531t = 15/9.8 \approx 1.531 s.

python · try it yourself
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 y′=e−x2y' = e^{-x^2}. The solution still exists and is perfectly well defined by the definite integral. You can name it (here ∫0xe−s2 ds=π2erf⁡(x)\int_0^x e^{-s^2}\,ds = \frac{\sqrt{\pi}}{2}\operatorname{erf}(x)) or compute it numerically:

python · try it yourself
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 * dt is a one-step approximation of x(t)=x0+∫v dtx(t) = x_0 + \int v\,dt.
  • Special functions such as math.erf, scipy.special.fresnel and scipy.special.expi exist precisely because these integrals come up so often that libraries tabulate them.

Exercises

Exercise 1: Fix the constant

Solve y′=cos⁡xy' = \cos x, y(0)=3y(0) = 3.

Answer

y=sin⁡x+3y = \sin x + 3.

Solution

y=sin⁡x+Cy = \sin x + C and y(0)=0+C=3y(0) = 0 + C = 3, so C=3C = 3.

Exercise 2: Braking distance

A car moving at 30 m/s brakes with constant deceleration 6 m/s2^2. How long does it take to stop, and how far does it travel?

Answer

5 s and 75 m.

Solution

v(t)=30−6t=0v(t) = 30 - 6t = 0 at t=5t = 5. Then x(5)=30⋅5−12⋅6⋅25=150−75=75x(5) = 30 \cdot 5 - \frac{1}{2}\cdot 6 \cdot 25 = 150 - 75 = 75 m.

Exercise 3: A definite-integral solution (code)

Solve y′=sin⁡xxy' = \frac{\sin x}{x}, y(0)=0y(0) = 0, and compute y(π)y(\pi) numerically.

Answer

y(π)=Si⁡(π)≈1.851937y(\pi) = \operatorname{Si}(\pi) \approx 1.851937.

Solution

y(x)=∫0xsin⁡ss dsy(x) = \int_0^x \frac{\sin s}{s}\,ds, the sine integral Si⁡(x)\operatorname{Si}(x).

python · try it yourself
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 y′=2xy' = 2x is…

  1. y=x2y = x^2
  2. y=x2+Cy = x^2 + C
  3. y=2y = 2
  4. y=2x+Cy = 2x + C

Why is y(x)=y0+∫x0xf(s) dsy(x) = y_0 + \int_{x_0}^x f(s)\,ds convenient?

  1. It avoids derivatives
  2. It satisfies y(x0)=y0y(x_0) = y_0 automatically and works even without an antiderivative formula
  3. It is always a polynomial
  4. It removes the need for ff

How many initial conditions does x′′=−9.8x'' = -9.8 need for a unique solution?

  1. None
  2. One
  3. Two
  4. Three