Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Calculus Essentials

Calculus is the language of change. In quantum mechanics we differentiate wavefunctions to build momentum and energy operators, and we integrate them to compute probabilities and expectation values. This page collects the essentials, with a picture for the two ideas that matter most: the derivative as a slope, and the integral as an area.

Differentiation

The derivative as a slope

The derivative of ff at a point is the slope of the line tangent to the curve there. We build it from the slope of a secant line through two nearby points and then let those points merge:

As the spacing hh shrinks, the secant line pivots into the tangent line. The plot below shows this for f(x)=x2f(x) = x^2 at x=1x = 1: three secant lines with shrinking hh close in on the true tangent of slope 2.

Source
import numpy as np
import matplotlib.pyplot as plt

f = lambda x: x**2
x0 = 1.0
x = np.linspace(-0.5, 2.5, 400)

fig, ax = plt.subplots(figsize=(6.5, 5))
ax.plot(x, f(x), 'k', lw=2, label=r'$f(x)=x^2$')

# Secant lines for shrinking h
for h, color in zip([1.0, 0.5, 0.2], ['#d1495b', '#edae49', '#66a182']):
    slope = (f(x0 + h) - f(x0)) / h
    sec = f(x0) + slope * (x - x0)
    ax.plot(x, sec, '--', color=color, lw=1.5, label=f'secant, h={h} (slope {slope:.1f})')
    ax.plot([x0, x0 + h], [f(x0), f(x0 + h)], 'o', color=color, ms=5)

# True tangent (slope 2)
ax.plot(x, f(x0) + 2 * (x - x0), color='#2e4057', lw=2, label='tangent (slope 2)')
ax.plot(x0, f(x0), 'ko', ms=6)

ax.set_xlim(-0.5, 2.5)
ax.set_ylim(-1, 6)
ax.set_xlabel('x')
ax.set_ylabel('f(x)')
ax.legend(fontsize=8, loc='upper left')
ax.set_title('Fig.1 Secant lines converging to the tangent as h shrinks')
plt.tight_layout()
plt.show()
<Figure size 650x500 with 1 Axes>

The derivative is also the instantaneous rate of change: if ff is position, ff' is velocity; if ff is concentration, ff' is reaction rate. A function is differentiable only where it is smooth, so no corners, jumps, or vertical tangents.

Rules of differentiation

RuleEquation
Constant multipleddx[cf(x)]=cf(x)\dfrac{d}{dx}[cf(x)] = c\,f'(x)
Sum and differenceddx[f(x)±g(x)]=f(x)±g(x)\dfrac{d}{dx}[f(x)\pm g(x)] = f'(x) \pm g'(x)
Productddx[f(x)g(x)]=f(x)g(x)+f(x)g(x)\dfrac{d}{dx}[f(x)g(x)] = f'(x)g(x) + f(x)g'(x)
Quotientddxf(x)g(x)=f(x)g(x)f(x)g(x)g(x)2\dfrac{d}{dx}\dfrac{f(x)}{g(x)} = \dfrac{f'(x)g(x) - f(x)g'(x)}{g(x)^2}
Powerddxxn=nxn1\dfrac{d}{dx} x^n = n\,x^{n-1}
Chainddxf(g(x))=f(g(x))g(x)\dfrac{d}{dx} f(g(x)) = f'(g(x))\cdot g'(x)
Linear approximationf(x)f(a)+f(a)(xa)f(x) \approx f(a) + f'(a)(x-a)

Table of common derivatives

Function f(x)f(x)Derivative f(x)f'(x)Function f(x)f(x)Derivative f(x)f'(x)
cc0xnx^nnxn1nx^{n-1}
exe^{x}exe^{x}lnx\ln x1x\dfrac{1}{x}
sinx\sin xcosx\cos xcosx\cos xsinx-\sin x
tanx\tan xsec2x\sec^2 xeaxe^{ax}aeaxa\,e^{ax}
arcsinx\arcsin x11x2\dfrac{1}{\sqrt{1-x^2}}arctanx\arctan x11+x2\dfrac{1}{1+x^2}

A few limits underlie these results: limθ0sinθθ=1\displaystyle\lim_{\theta\to 0}\frac{\sin\theta}{\theta}=1, limθ0cosθ1θ=0\displaystyle\lim_{\theta\to 0}\frac{\cos\theta-1}{\theta}=0, and the definition limh0eh1h=1\displaystyle\lim_{h\to 0}\frac{e^{h}-1}{h}=1, which is exactly what makes exe^{x} its own derivative.

Integration

The integral as accumulated area

A definite integral measures the net area between a curve and the xx axis. We approximate that area with a Riemann sum of nn rectangles and let nn\to\infty:

The plot shows the rectangles filling the area under f(x)=x2f(x)=x^2 on [0,2][0,2] as nn grows from coarse to fine. The exact area is 02x2dx=8/32.667\int_0^2 x^2\,dx = 8/3 \approx 2.667.

Source
import numpy as np
import matplotlib.pyplot as plt

f = lambda x: x**2
a, b = 0, 2
xs = np.linspace(a, b, 400)

fig, axes = plt.subplots(1, 3, figsize=(11, 3.6), sharey=True)
for ax, n in zip(axes, [4, 8, 32]):
    edges = np.linspace(a, b, n + 1)
    mids = 0.5 * (edges[:-1] + edges[1:])   # midpoint rule
    dx = (b - a) / n
    approx = np.sum(f(mids) * dx)
    ax.bar(mids, f(mids), width=dx, align='center',
           color='#66a182', edgecolor='white', alpha=0.7)
    ax.plot(xs, f(xs), 'k', lw=2)
    ax.set_title(f'n = {n},  sum = {approx:.3f}', fontsize=10)
    ax.set_xlabel('x')
axes[0].set_ylabel('f(x)')
plt.suptitle('Fig.2 Riemann sums approaching the exact area 8/3 = 2.667 as n grows', y=1.04)
plt.tight_layout()
plt.show()
<Figure size 1100x360 with 3 Axes>

We can watch that convergence numerically:

import numpy as np

f = lambda x: x**2
a, b = 0.0, 2.0
for n in [4, 16, 64, 256, 1024]:
    x = np.linspace(a, b, n + 1)
    mids = 0.5 * (x[:-1] + x[1:])
    approx = np.sum(f(mids) * (b - a) / n)
    print(f"n = {n:5d}   Riemann sum = {approx:.5f}")

exact = 8 / 3
print(f"\nexact value  = {exact:.5f}")
n =     4   Riemann sum = 2.62500
n =    16   Riemann sum = 2.66406
n =    64   Riemann sum = 2.66650
n =   256   Riemann sum = 2.66666
n =  1024   Riemann sum = 2.66667

exact value  = 2.66667

Antiderivatives and the fundamental theorem

An antiderivative FF of ff satisfies F(x)=f(x)F'(x)=f(x). Because the derivative of a constant is zero, antiderivatives come as a family F(x)+CF(x)+C. The fundamental theorem of calculus ties the two halves of the subject together:

This is why we rarely compute Riemann sums by hand: finding an antiderivative turns an infinite sum into a single subtraction.

Table of indefinite integrals

Function f(x)f(x)Antiderivative F(x)F(x)Function f(x)f(x)Antiderivative F(x)F(x)
xn (n1)x^n\ (n\neq -1)xn+1n+1+C\dfrac{x^{n+1}}{n+1} + C1x\dfrac{1}{x}lnx+C\ln\lvert x \rvert + C
exe^{x}ex+Ce^{x} + Ceaxe^{ax}1aeax+C\dfrac{1}{a}e^{ax} + C
sinx\sin xcosx+C-\cos x + Ccosx\cos xsinx+C\sin x + C
1x2+a2\dfrac{1}{x^2 + a^2}1aarctan ⁣(xa)+C\dfrac{1}{a}\arctan\!\left(\dfrac{x}{a}\right) + C1a2x2\dfrac{1}{\sqrt{a^2-x^2}}arcsin ⁣(xa)+C\arcsin\!\left(\dfrac{x}{a}\right) + C

Useful properties: reversing the limits flips the sign, aafdx=0\int_a^a f\,dx = 0, and integrals are linear, (cf±g)dx=cfdx±gdx\int (cf \pm g)\,dx = c\int f\,dx \pm \int g\,dx. For symmetric limits, an even function gives aafdx=20afdx\int_{-a}^{a} f\,dx = 2\int_0^a f\,dx while an odd function gives aafdx=0\int_{-a}^{a} f\,dx = 0, a shortcut that kills many quantum-mechanical integrals on sight.

Techniques of integration

Integration by parts is the reverse of the product rule, and it is the standard tool for integrals like xexdx\int x\,e^{-x}\,dx or xsinxdx\int x\sin x\,dx that appear constantly in expectation-value calculations.

For products of sines and cosines, the power-reduction and product-to-sum identities do the work:

sin2x=12(1cos2x),cos2x=12(1+cos2x),\sin^2 x = \tfrac{1}{2}(1-\cos 2x), \qquad \cos^2 x = \tfrac{1}{2}(1+\cos 2x),
sinAsinB=12[cos(AB)cos(A+B)],cosAcosB=12[cos(AB)+cos(A+B)].\sin A\sin B = \tfrac{1}{2}\big[\cos(A-B)-\cos(A+B)\big], \qquad \cos A\cos B = \tfrac{1}{2}\big[\cos(A-B)+\cos(A+B)\big].

These are exactly the integrals that enforce orthogonality of particle-in-a-box wavefunctions.

Problems

Problem 1: Differentiate a Gaussian

Differentiate f(x)=eαx2f(x) = e^{-\alpha x^2} with respect to xx.

Problem 2: Product and chain together

Differentiate g(x)=xsin(kx)g(x) = x\sin(kx).

Problem 3: A normalization integral

Evaluate 0Lsin2 ⁣(πxL)dx\displaystyle\int_0^{L} \sin^2\!\left(\frac{\pi x}{L}\right)dx.

Problem 4: Integration by parts

Evaluate 0xexdx\displaystyle\int_0^{\infty} x\,e^{-x}\,dx.

Problem 5: Symmetry shortcut

Without computing an antiderivative, evaluate aaxex2dx\displaystyle\int_{-a}^{a} x\,e^{-x^2}\,dx.

Problem 6: Verify a Riemann sum numerically

Modify the Riemann-sum code above to estimate 0πsinxdx\int_0^{\pi}\sin x\,dx and compare with the exact value 2.

Problem 7: Chain rule on a plane wave

Differentiate ψ(x)=eikx\psi(x) = e^{ikx} with respect to xx, and again to find ψ(x)\psi''(x).

Problem 8: An expectation-value integral

Evaluate 0x2exdx\displaystyle\int_0^{\infty} x^2\,e^{-x}\,dx using integration by parts twice.