The derivative f'(a) is the slope of the tangent line at x = a. It is defined as the limit of the difference quotient: f'(a) = limh→0 [f(a+h) - f(a)] / h. If this limit exists, f is differentiable at a.
The difference quotient
The slope of the secant line through (a, f(a)) and (a+h, f(a+h)) is [f(a+h) - f(a)] / h. As h shrinks to zero, this secant slope approaches the tangent slope. That limit is the derivative.
# Difference quotient approaching derivative
f = lambda x: x**2
a = 3for h in [1.0, 0.1, 0.01, 0.001, 0.0001]:
slope = (f(a + h) - f(a)) / h
print(f"h={h:<8} slope = {slope:.6f}")
print("Limit = 6 = 2*3")
Derivative as a function
We can compute f'(x) for every x, not just one point. The result is a new function. For f(x) = x², the derivative f'(x) = 2x. The derivative maps each input to the slope of f at that input.
A function is differentiable at a if the limit exists. Differentiable implies continuous, but not the other way around. |x| is continuous at 0 but not differentiable: the left and right slopes disagree.
Scheme
; |x| is continuous at 0 but not differentiable; Left slope = -1, right slope = +1
(define (abs-val x) (if (< x 0) (- x) x))
; Approach from right (h > 0)
(define (right-slope h)
(/ (- (abs-val h) (abs-val 0)) h))
; Approach from left (h < 0)
(define (left-slope h)
(/ (- (abs-val h) (abs-val 0)) h))
(display "Right slopes:") (newline)
(display "h=0.1: ") (display (right-slope 0.1)) (newline)
(display "h=0.01: ") (display (right-slope 0.01)) (newline)
(display "Left slopes:") (newline)
(display "h=-0.1: ") (display (left-slope -0.1)) (newline)
(display "h=-0.01: ") (display (left-slope -0.01)) (newline)
(display "Left limit = -1, Right limit = +1") (newline)
(display "Not equal: |x| is not differentiable at 0")
Python
# |x| is continuous at 0 but not differentiable# Left slope = -1, right slope = +1print("Right slopes:")
for h in [0.1, 0.01]:
print(" h={}: {}".format(h, abs(h) / h))
print("Left slopes:")
for h in [-0.1, -0.01]:
print(" h={}: {}".format(h, abs(h) / h))
print("Left limit = -1, Right limit = +1")
print("Not equal: |x| is not differentiable at 0")
Tangent line equation
The tangent line at x = a is y = f(a) + f'(a)(x - a). This is the best linear approximation to f near a. It is the foundation of linearization, Newton's method, and Taylor series.
Scheme
; Tangent line: y = f(a) + f'(a)(x - a); f(x) = x^2 at a = 2: f(2) = 4, f'(2) = 4; Tangent: y = 4 + 4(x - 2) = 4x - 4
(define (f x) (* x x))
(define (f-prime x) (* 2 x)) ; known derivative
(define a 2)
(define (tangent x)
(+ (f a) (* (f-prime a) (- x a))))
(display "x=1.5: f=") (display (f 1.5)) (display " tangent=") (display (tangent 1.5)) (newline)
(display "x=2.0: f=") (display (f 2.0)) (display " tangent=") (display (tangent 2.0)) (newline)
(display "x=2.5: f=") (display (f 2.5)) (display " tangent=") (display (tangent 2.5)) (newline)
(display "x=3.0: f=") (display (f 3.0)) (display " tangent=") (display (tangent 3.0)) (newline)
(display "Tangent approximation is good near a, worse far away")
Python
# Tangent line: y = f(a) + f'(a)(x - a)# f(x) = x^2 at a = 2
f = lambda x: x**2
f_prime = lambda x: 2*x
a = 2
tangent = lambda x: f(a) + f_prime(a) * (x - a)
for x in [1.5, 2.0, 2.5, 3.0]:
print("x={}: f={} tangent={}".format(x, f(x), tangent(x)))
print("Tangent approximation is good near a, worse far away")
Notation reference
Math
Scheme
Meaning
f'(x)
(f-prime x)
Derivative of f at x
dy/dx
(deriv f)
Leibniz notation for derivative
[f(a+h)-f(a)]/h
(diff-quotient h)
Difference quotient
limh→0
h = 0.00001
Limit (approximated numerically)
Neighbors
∫ Ch.3 Limits — the derivative is defined as a limit