TExcelTAD
Home › Calculus in Depth › Antiderivatives

Antiderivatives

Differentiation goes from a function to its rate of change. Antidifferentiation goes back: given the rate, recover the function. This lesson defines antiderivatives, proves that they all differ by a constant, builds the basic table, and uses initial conditions to solve motion problems, the same reconstruction a game engine does every frame. For a first look see Antiderivatives.

Definition and the "+C+ C"

A function FF is an antiderivative of ff on an interval II if F′(x)=f(x)F'(x) = f(x) for all xx in II.

Theorem. If FF is an antiderivative of ff on an interval II, then every antiderivative of ff on II has the form F(x)+CF(x) + C for a constant CC.

Proof. If G′=f=F′G' = f = F' on II, then (G−F)′=0(G - F)' = 0 on II, so by the Mean Value Theorem G−FG - F is constant there. ∎

The word interval matters. On the domain x≠0x \ne 0, the function

G(x)={ln⁡x+1for x>0ln⁡(−x)−4for x<0G(x) = \begin{cases} \ln x + 1 & \text{for } x > 0 \\ \ln(-x) - 4 & \text{for } x < 0 \end{cases}

is an antiderivative of 1/x1/x and is not of the form ln⁡∣x∣+C\ln\lvert x \rvert + C with one constant: each piece of the domain gets its own constant.

The basic table

Read each derivative formula backwards (valid on any interval where both sides are defined):

f(x)f(x) antiderivative F(x)F(x)
xnx^n (n≠−1n \ne -1) xn+1n+1\frac{x^{n+1}}{n + 1}
1/x1/x ln⁡∣x∣\ln\lvert x \rvert
exe^{x}, axa^x exe^{x}, ax/ln⁡aa^x/\ln a
cos⁡x\cos x, sin⁡x\sin x sin⁡x\sin x, −cos⁡x-\cos x
sec⁡2x\sec^2 x, sec⁡xtan⁡x\sec x \tan x tan⁡x\tan x, sec⁡x\sec x
11−x2\frac{1}{\sqrt{1 - x^2}} sin⁡−1x\sin^{-1} x
11+x2\frac{1}{1 + x^2} tan⁡−1x\tan^{-1} x
cosh⁡x\cosh x, sinh⁡x\sinh x sinh⁡x\sinh x, cosh⁡x\cosh x
c⋅f(x)+g(x)c \cdot f(x) + g(x) c⋅F(x)+G(x)c \cdot F(x) + G(x) (linearity)

Every entry can be checked by differentiating the right column. That check, "differentiate your answer", is the single most useful habit in integration. SymPy can do it for you; note that it omits the +C+ C:

python · try it yourself
import sympy as sp

x = sp.symbols('x', positive=True)
fs = [3*x**4 - 2/sp.sqrt(x), 5*sp.exp(x) + 2**x, 4/(1 + x**2), sp.sec(x)**2 - 6*sp.cos(x)]
for f in fs:
    F = sp.integrate(f, x)
    ok = sp.simplify(sp.diff(F, x) - f) == 0
    print(f"f = {str(f):28}  F = {str(F):36} F' == f: {ok}")
f = 3*x**4 - 2/sqrt(x)            F = -4*sqrt(x) + 3*x**5/5                F' == f: True
f = 2**x + 5*exp(x)               F = 2**x/log(2) + 5*exp(x)               F' == f: True
f = 4/(x**2 + 1)                  F = 4*atan(x)                            F' == f: True
f = -6*cos(x) + sec(x)**2         F = -6*sin(x) + sin(x)/cos(x)            F' == f: True

SymPy writes log for ln⁡\ln, atan for tan⁡−1\tan^{-1}, and here chose sin(x)/cos(x) for tan⁡x\tan x. Different-looking answers can be equal, or differ by a constant; differentiating settles it.

Initial value problems

An equation like f′(x)=g(x)f'(x) = g(x) together with a value f(a)=bf(a) = b fixes the constant. Higher derivatives need one condition per antidifferentiation.

Example. f′′(x)=6x−4f''(x) = 6x - 4, f(0)=3f(0) = 3, f(1)=2f(1) = 2.

f′(x)=3x2−4x+Cf(x)=x3−2x2+Cx+Df(0)=D=3f(1)=1−2+C+3=2⇒C=0f(x)=x3−2x2+3\begin{aligned} f'(x) &= 3x^2 - 4x + C \\ f(x) &= x^3 - 2x^2 + Cx + D \\ f(0) &= D = 3 \\ f(1) &= 1 - 2 + C + 3 = 2 \quad \Rightarrow \quad C = 0 \\ f(x) &= x^3 - 2x^2 + 3 \end{aligned}
python · try it yourself
import sympy as sp

x = sp.symbols('x')
f = sp.Function('f')
sol = sp.dsolve(sp.Eq(f(x).diff(x, 2), 6*x - 4), f(x), ics={f(0): 3, f(1): 2})
print(sol)
Eq(f(x), x**3 - 2*x**2 + 3)

Rectilinear motion

If s(t)s(t) is position, then v=s′v = s' and a=v′=s′′a = v' = s''. Given the acceleration and the initial velocity and position, two antiderivatives recover the motion. A ball thrown upward at v0=15 m/sv_0 = 15\ \text{m/s} from a 20 m ledge, with a=−9.8 m/s2a = -9.8\ \text{m/s}^2:

v(t)=−9.8t+15s(t)=−4.9t2+15t+20\begin{aligned} v(t) &= -9.8t + 15 \\ s(t) &= -4.9t^2 + 15t + 20 \end{aligned}

It peaks when v=0v = 0, at t=15/9.8≈1.531 st = 15/9.8 \approx 1.531\ \text{s}, and lands when s=0s = 0, at the positive root of −4.9t2+15t+20=0-4.9t^2 + 15t + 20 = 0.

What a physics engine does

A game engine does not know s(t)s(t) in closed form. It knows the acceleration and antidifferentiates numerically, frame by frame: v += a·dt, then x += v·dt (semi-implicit Euler). For constant acceleration the error comes only from the time step, and we can compare it with the exact antiderivative:

python · try it yourself
import math

g, v0, s0 = -9.8, 15.0, 20.0
t_land = (-v0 - math.sqrt(v0**2 - 4 * (g / 2) * s0)) / g    # positive root, quadratic formula
print(f"exact: peak at t = {v0 / -g:.4f} s, height {s0 + v0**2 / (2 * -g):.4f} m, lands at t = {t_land:.4f} s")

for dt in (1 / 30, 1 / 60, 1 / 240):
    s, v, t = s0, v0, 0.0
    while True:
        v += g * dt               # antiderivative of a
        s_new = s + v * dt        # antiderivative of v
        if s_new <= 0:
            t += dt * s / (s - s_new)     # interpolate the landing time
            break
        s, t = s_new, t + dt
    print(f"dt = 1/{round(1 / dt):3}: lands at t = {t:.4f} s (error {t - t_land:+.4f})")
exact: peak at t = 1.5306 s, height 31.4796 m, lands at t = 4.0653 s
dt = 1/ 30: lands at t = 4.0385 s (error -0.0267)
dt = 1/ 60: lands at t = 4.0519 s (error -0.0134)
dt = 1/240: lands at t = 4.0619 s (error -0.0033)

Halving dt roughly halves the error: the method is first-order. Better integrators (Verlet, RK4) are covered in Game Physics Integration.

In software

  • Physics and animation: positions are antiderivatives of velocities, which are antiderivatives of accelerations. Every engine's integrator is a numerical antiderivative.
  • Prefix sums: the discrete analogue of an antiderivative is a running total (itertools.accumulate, np.cumsum); a difference of two prefix sums answers a range query in O(1), just as F(b)−F(a)F(b) - F(a) will give a definite integral in the Fundamental Theorem.
  • Odometry and dead reckoning: robots and phones integrate accelerometer and gyroscope data to estimate position. The unknown +C+ C (initial conditions) and accumulated error are why they drift without GPS.

Exercises

Exercise 1: General antiderivative

Find the general antiderivative of f(x)=4x3−3x2+2cos⁡xf(x) = 4x^3 - \frac{3}{x^2} + 2\cos x.

Answer

F(x)=x4+3x+2sin⁡x+CF(x) = x^4 + \frac{3}{x} + 2\sin x + C (one constant on each interval of x>0x > 0 and x<0x < 0).

Solution
∫4x3=x4,∫−3x−2=−3⋅x−1−1=3x,∫2cos⁡x=2sin⁡xcheck: (3x)′=−3x2 ✓\begin{aligned} &\int 4x^3 = x^4, \qquad \int -3x^{-2} = -3 \cdot \frac{x^{-1}}{-1} = \frac{3}{x}, \qquad \int 2\cos x = 2\sin x \\ &\text{check: } \left(\frac{3}{x}\right)' = -\frac{3}{x^2} \ \checkmark \end{aligned}

Exercise 2: An initial value problem

Find ff with f′(x)=ex+11+x2f'(x) = e^{x} + \frac{1}{1 + x^2} and f(0)=5f(0) = 5.

Answer

f(x)=ex+tan⁡−1x+4f(x) = e^{x} + \tan^{-1} x + 4.

Solution

f(x)=ex+tan⁡−1x+Cf(x) = e^{x} + \tan^{-1} x + C; f(0)=1+0+C=5⇒C=4f(0) = 1 + 0 + C = 5 \Rightarrow C = 4.

python · try it yourself
import sympy as sp
x = sp.symbols('x')
f = sp.Function('f')
print(sp.dsolve(sp.Eq(f(x).diff(x), sp.exp(x) + 1 / (1 + x**2)), f(x), ics={f(0): 5}))
Eq(f(x), exp(x) + atan(x) + 4)

Exercise 3: Braking distance

A car at 30 m/s brakes with constant deceleration 6 m/s26\ \text{m/s}^2. How far does it travel before stopping?

Answer

75 m75\ \text{m} (it stops after 5 s).

Solution
v(t)=30−6t=0⇒t=5s(t)=30t−3t2,s(5)=150−75=75\begin{aligned} &v(t) = 30 - 6t = 0 \Rightarrow t = 5 \\ &s(t) = 30t - 3t^2, \quad s(5) = 150 - 75 = 75 \end{aligned}

Exercise 4: Two constants from a graph

f′′(x)=12x2f''(x) = 12x^2, the graph passes through (1,2)(1, 2) and has slope −1-1 there. Find ff.

Answer

f(x)=x4−5x+6f(x) = x^4 - 5x + 6.

Solution
f′(x)=4x3+C,f′(1)=4+C=−1⇒C=−5f(x)=x4−5x+D,f(1)=1−5+D=2⇒D=6\begin{aligned} &f'(x) = 4x^3 + C, \quad f'(1) = 4 + C = -1 \quad \Rightarrow \quad C = -5 \\ &f(x) = x^4 - 5x + D, \quad f(1) = 1 - 5 + D = 2 \quad \Rightarrow \quad D = 6 \end{aligned}

Test yourself

Why do two antiderivatives of ff on an interval differ by a constant?

  1. Their difference has derivative 0, so it is constant by the Mean Value Theorem
  2. By definition
  3. Because ff is continuous
  4. By the chain rule

Which is an antiderivative of 2x2^x?

  1. 2x2^x
  2. x⋅2x−1x \cdot 2^{x-1}
  3. 2x/ln⁡22^x / \ln 2
  4. 2x+1/(x+1)2^{x+1} / (x + 1)

How many initial conditions are needed to pin down ff if you know f′′′f'''?

  1. 1
  2. 3
  3. 2
  4. None