TExcelTAD
Home › Calculus Essentials › Antiderivatives

Antiderivatives

An antiderivative runs differentiation backwards. If you know how fast something changes, the antiderivative tells you what the thing itself looks like. This is how a game gets a position from a velocity, and how a physics engine gets a velocity from an acceleration.

The idea

A function FF is an antiderivative of ff when F′(x)=f(x)F'(x) = f(x). Differentiation asks "what is the slope of this curve?". Antidifferentiation asks the reverse question: "which curve has this slope everywhere?".

For example F(x)=x3F(x) = x^3 is an antiderivative of f(x)=3x2f(x) = 3x^2, because ddxx3=3x2\frac{d}{dx} x^3 = 3x^2. But so is x3+5x^3 + 5, and x3−100x^3 - 100. A constant disappears when you differentiate, so it can be anything when you go back. The complete answer is a whole family of functions:

∫3x2 dx=x3+C(C is any constant)\int 3x^2\,dx = x^3 + C \qquad (C \text{ is any constant})

The symbol ∫… dx\int \ldots\,dx is the indefinite integral, the notation for "all antiderivatives of". CC is the constant of integration. Graphically, the family is one curve shifted up and down: every member has the same slope at each xx.

Note: Two antiderivatives of the same function on an interval always differ by a constant. That is why one + C+\,C covers every possible answer.

A starter table

Every row comes from reading a derivative rule backwards. You can check any of them by differentiating the right-hand side.

f(x)f(x) ∫f(x) dx\int f(x)\,dx Check
kk (a constant) kx+Ckx + C ddxkx=k\frac{d}{dx} kx = k
xnx^n (n≠−1n \ne -1) xn+1n+1+C\frac{x^{n+1}}{n + 1} + C power rule
1/x1/x ln⁡∣x∣+C\ln\lvert x \rvert + C ddxln⁡∣x∣=1/x\frac{d}{dx} \ln\lvert x \rvert = 1/x
exe^x ex+Ce^x + C exe^x is its own derivative
cos⁡x\cos x sin⁡x+C\sin x + C ddxsin⁡x=cos⁡x\frac{d}{dx} \sin x = \cos x
sin⁡x\sin x −cos⁡x+C-\cos x + C ddx(−cos⁡x)=sin⁡x\frac{d}{dx} (-\cos x) = \sin x
sec⁡2x\sec^2 x tan⁡x+C\tan x + C ddxtan⁡x=sec⁡2x\frac{d}{dx} \tan x = \sec^2 x

The power rule fails for n=−1n = -1 because it would divide by zero; that gap is filled by ln⁡∣x∣\ln\lvert x \rvert.

Checking with SymPy

SymPy's integrate returns one antiderivative and leaves out the + C+\,C. Differentiating the result must give the original function back, which is a habit worth copying when you integrate by hand.

python · try it yourself
import sympy as sp

x = sp.symbols("x")
for f in [3 * x**2, x**5, 1 / x, sp.exp(x), sp.sin(x), 1 / sp.sqrt(x)]:
    F = sp.integrate(f, x)
    back = sp.simplify(sp.diff(F, x) - f)
    print(f"f = {str(f):12} F = {str(F):12} F' - f = {back}")
f = 3*x**2       F = x**3         F' - f = 0
f = x**5         F = x**6/6       F' - f = 0
f = 1/x          F = log(x)       F' - f = 0
f = exp(x)       F = exp(x)       F' - f = 0
f = sin(x)       F = -cos(x)      F' - f = 0
f = 1/sqrt(x)    F = 2*sqrt(x)    F' - f = 0

SymPy writes log(x) for the natural log and does not add the absolute value; on x>0x > 0 it is the same thing.

Pinning down C with a starting value

The constant is fixed by one known value, an initial condition. A ball is thrown up at 12 m/s from a height of 2 m. Gravity gives the acceleration a(t)=−9.8a(t) = -9.8. Integrate twice:

v(t)=∫−9.8 dt=−9.8t+C1v(0)=12→C1=12s(t)=∫(−9.8t+12) dt=−4.9t2+12t+C2s(0)=2→C2=2s(t)=−4.9t2+12t+2\begin{aligned} v(t) &= \int -9.8\,dt = -9.8t + C_1 && v(0) = 12 \to C_1 = 12 \\ s(t) &= \int (-9.8t + 12)\,dt = -4.9t^2 + 12t + C_2 && s(0) = 2 \to C_2 = 2 \\ s(t) &= -4.9t^2 + 12t + 2 \end{aligned}
python · try it yourself
import sympy as sp

t, C1, C2 = sp.symbols("t C1 C2")
v = sp.integrate(-9.8, t) + C1
v = v.subs(C1, sp.solve(v.subs(t, 0) - 12, C1)[0])
s = sp.integrate(v, t) + C2
s = s.subs(C2, sp.solve(s.subs(t, 0) - 2, C2)[0])
print("v(t) =", v)
print("s(t) =", s)
t_top = sp.solve(v, t)[0]
print("highest point at t =", round(float(t_top), 4), "s, height", round(float(s.subs(t, t_top)), 4), "m")
v(t) = 12 - 9.8*t
s(t) = -4.9*t**2 + 12.0*t + 2
highest point at t = 1.2245 s, height 9.3469 m

In software

A game cannot run SymPy every frame. It antidifferentiates numerically: each frame it adds velocity⋅dt\text{velocity} \cdot dt to the position, which is a tiny step of "position=antiderivative of velocity\text{position} = \text{antiderivative of velocity}". Done with a small time step, it tracks the exact formula closely:

python · try it yourself
dt = 1 / 60                  # one frame at 60 fps
y, v = 2.0, 12.0             # start height and velocity
for frame in range(60):      # simulate one second
    v += -9.8 * dt           # velocity = antiderivative of acceleration
    y += v * dt              # position = antiderivative of velocity
exact = -4.9 * 1**2 + 12 * 1 + 2
print(f"game loop after 1 s: y = {y:.4f}")
print(f"exact formula      : y = {exact:.4f}")
print(f"difference         : {y - exact:.4f} m")
game loop after 1 s: y = 9.0183
exact formula      : y = 9.1000
difference         : -0.0817 m

The small gap is the price of taking steps instead of integrating exactly; Numerical Integration and Physics Integration in Game Loops look at it closely, and Integrators compares the schemes engines use.

Exercises

Exercise 1: Read the table backwards

Find ∫(4x3−6x+2) dx\int (4x^3 - 6x + 2)\,dx.

Answer

x4−3x2+2x+Cx^4 - 3x^2 + 2x + C

Solution
∫4x3 dx=4⋅x44=x4∫−6x dx=−6⋅x22=−3x2∫2 dx=2xcheck: ddx(x4−3x2+2x)=4x3−6x+2 ✓\begin{aligned} &\int 4x^3\,dx = 4 \cdot \frac{x^4}{4} = x^4 \\ &\int -6x\,dx = -6 \cdot \frac{x^2}{2} = -3x^2 \\ &\int 2\,dx = 2x \\ &\text{check: } \frac{d}{dx} (x^4 - 3x^2 + 2x) = 4x^3 - 6x + 2 \ \checkmark \end{aligned}

Exercise 2: Roots and negative powers

Find ∫(x+1x2)dx\int \left(\sqrt{x} + \dfrac{1}{x^2}\right) dx.

Answer

23x3/2−1x+C\frac{2}{3}x^{3/2} - \frac{1}{x} + C

Solution
x=x1/2→x3/23/2=23x3/21x2=x−2→x−1−1=−1x\begin{aligned} \sqrt{x} &= x^{1/2} &&\to \frac{x^{3/2}}{3/2} = \tfrac{2}{3} x^{3/2} \\ \frac{1}{x^2} &= x^{-2} &&\to \frac{x^{-1}}{-1} = -\frac{1}{x} \end{aligned}

Exercise 3: Find the particular function

f′(x)=6x+cos⁡xf'(x) = 6x + \cos x and f(0)=4f(0) = 4. Find f(x)f(x).

Answer

f(x)=3x2+sin⁡x+4f(x) = 3x^2 + \sin x + 4

Solution
f(x)=3x2+sin⁡x+Cf(0)=0+sin⁡0+C=C=4\begin{aligned} f(x) &= 3x^2 + \sin x + C \\ f(0) &= 0 + \sin 0 + C = C = 4 \end{aligned}

Exercise 4: Braking car

A car moving at 30 m/s brakes with constant acceleration −6 m/s2-6\ \text{m/s}^2. Find its position function (start at 0) and how far it travels before it stops. Check with Python.

Answer

s(t)=30t−3t2s(t) = 30t - 3t^2; it stops at t=5 st = 5\ \text{s} after 75 m75\ \text{m}.

Solution
v(t)=∫−6 dt=−6t+30(v(0)=30)s(t)=∫(−6t+30) dt=−3t2+30t(s(0)=0)v=0→t=5,s(5)=−75+150=75\begin{aligned} v(t) &= \int -6\,dt = -6t + 30 && (v(0) = 30) \\ s(t) &= \int (-6t + 30)\,dt = -3t^2 + 30t && (s(0) = 0) \\ v &= 0 \to t = 5, \quad s(5) = -75 + 150 = 75 \end{aligned}
python · try it yourself
import sympy as sp

t = sp.symbols("t")
v = 30 + sp.integrate(-6, t)
s = sp.integrate(v, t)
t_stop = sp.solve(v, t)[0]
print("s(t) =", s, " stops at t =", t_stop, " distance =", s.subs(t, t_stop))
s(t) = -3*t**2 + 30*t  stops at t = 5  distance = 75

Test yourself

Which function is an antiderivative of cos⁡x\cos x?

  1. −sin⁡x-\sin x
  2. sin⁡x+7\sin x + 7
  3. cos⁡x\cos x
  4. −cos⁡x-\cos x

Why does an indefinite integral carry + C+\,C?

  1. It is a rounding correction
  2. SymPy needs it
  3. Constants differentiate to zero, so any constant could have been there
  4. It marks the variable of integration

Why does ∫xn dx=xn+1n+1\int x^n\,dx = \frac{x^{n+1}}{n+1} not work for n=−1n = -1?

  1. It would divide by zero; the answer is ln⁡∣x∣\ln\lvert x \rvert instead
  2. 1/x1/x has no antiderivative
  3. Negative powers cannot be integrated
  4. It works fine