Derivatives answer practical questions: Where is the maximum? How fast is something changing? What does the curve look like? Optimization finds extrema where f'(x) = 0. L'Hopital's rule evaluates indeterminate limits. Newton's method finds roots by chasing tangent lines.
Finding maxima and minima
Critical points are where f'(x) = 0 or f'(x) is undefined. To classify them: f''(x) > 0 means local minimum, f''(x) < 0 means local maximum. This is the second derivative test.
# Find extrema of f(x) = x^3 - 3x + 1
f = lambda x: x**3 - 3*x + 1
fp = lambda x: 3*x**2 - 3
fpp = lambda x: 6*x
for x in [-1, 1]:
kind = "MAX"if fpp(x) < 0else"MIN"print(f"x={x}: f={f(x)}, f'={fp(x)}, f''={fpp(x)} -> {kind}")
Related rates
If two quantities are related by an equation and both change with time, differentiate the equation with respect to t. You get a relationship between their rates. Classic example: a balloon inflating, how fast does the radius grow when the volume grows at a known rate?
Scheme
; Related rates: sphere volume V = (4/3) pi r^3; dV/dt = 4 pi r^2 (dr/dt); Given dV/dt = 100 cm^3/s, find dr/dt when r = 5
(define pi 3.141592653589793)
(define r 5)
(define dV-dt 100)
; dr/dt = dV/dt / (4 pi r^2)
(define dr-dt (/ dV-dt (* 4 pi r r)))
(display "When r = 5 and dV/dt = 100:") (newline)
(display "dr/dt = ") (display (/ (round (* dr-dt 10000)) 10000))
(display " cm/s")
Python
importmath# Related rates: sphere V = (4/3) pi r^3# dV/dt = 4 pi r^2 (dr/dt)# Solve for dr/dt
r = 5
dV_dt = 100
dr_dt = dV_dt / (4 * math.pi * r**2)
print("When r = 5 and dV/dt = 100:")
print("dr/dt = {:.4f} cm/s".format(dr_dt))
L'Hopital's rule
If lim f(x)/g(x) is 0/0 or ∞/∞, then it equals lim f'(x)/g'(x) (when that limit exists). This resolves indeterminate forms mechanically.
To find a root of f(x) = 0, Newton's method starts with a guess x₀ and iterates: xₙ₊¹ = xₙ - f(xₙ)/f'(xₙ). Each step follows the tangent line to the x-axis. Convergence is quadratic when it works.
Scheme
; Newton's method: find sqrt(2) by solving x^2 - 2 = 0; f(x) = x^2 - 2, f'(x) = 2x; x_next = x - f(x)/f'(x) = x - (x^2-2)/(2x)
(define (f x) (- (* x x) 2))
(define (f-prime x) (* 2 x))
(define (newton x n)
(display "x_") (display n) (display " = ") (display x)
(display " f(x) = ") (display (/ (round (* (f x) 1000000)) 1000000))
(newline)
(if (= n 6) x
(newton (- x (/ (f x) (f-prime x))) (+ n 1))))
(newton 2.00)
; Converges to sqrt(2) = 1.41421356...
Python
# Newton's method: find sqrt(2) by solving x^2 - 2 = 0
f = lambda x: x**2 - 2
fp = lambda x: 2*x
x = 2.0for n inrange(7):
print("x_{} = {:.10f} f(x) = {:.10f}".format(n, x, f(x)))
x = x - f(x)/fp(x)
# Converges to sqrt(2) = 1.41421356...
Curve sketching
The first derivative tells you where f is increasing (f' > 0) or decreasing (f' < 0). The second derivative tells you concavity: concave up (f'' > 0) or concave down (f'' < 0). Inflection points are where concavity changes.