Two-point formulas for numerical differentiation
Lesson: approximate first derivatives using pairs of nearby function values.
Exercise 1 – Compare two-point formulas on eˣ
Use f(x) = eˣ and approximate f′(x₀) at a chosen x₀ using forward, backward, and central differences with step size h.
Hint
Compare each approximation with the exact derivative f′(x₀) = eˣ₀ and observe how the error behaves when you reduce h.
Higher-order derivative formulas
Lesson: use finite-difference stencils to approximate second derivatives.
Exercise 2 – Approximate the second derivative of sin(x)
For f(x) = sin(x) the exact second derivative is f″(x) = −sin(x). Compare the finite-difference approximation with the exact value at a chosen x₀ and step size h.
Stencil formula
Three-point central formula for the second derivative:
f''(x0) ≈ [ f(x0 + h) - 2 f(x0) + f(x0 - h) ] / h^2
This approximation is based on Taylor expansions of f around x0.
Rectangle (midpoint) rule
Lesson: approximate definite integrals using rectangles centered in subintervals.
Exercise 3 – Midpoint rule for ∫₀¹ eˣ dx
The exact value of ∫₀¹ eˣ dx is e − 1. Use the midpoint rule with n subintervals to approximate the integral and compare the absolute error.
Formula
For a function f on [a, b] and n subintervals:
Δx = (b - a) / n
m_i = a + (i - 0.5) Δx, i = 1, ..., n
Midpoint rule:
M_n = Δx * Σ_{i=1}^n f(m_i).
Trapezoidal vs rectangle rules
Lesson: compare two basic quadrature rules on the same integral.
Exercise 4 – Compare trapezoidal and midpoint errors for sin(x)
Consider ∫₀^π sin(x) dx, whose exact value is 2. Compute both midpoint and trapezoidal approximations with n subintervals and compare the absolute errors.
Trapezoidal formula
Trapezoidal rule on [a, b] with n subintervals:
Δx = (b - a) / n
x_i = a + i Δx
T_n = (Δx / 2) * [ f(x_0) + 2 Σ_{i=1}^{n-1} f(x_i) + f(x_n) ].
Simpson’s rule on practical examples
Lesson: combine endpoint and midpoint information to get higher accuracy.
Exercise 5 – Compare three rules on 1 / (1 + x²)
Use f(x) = 1 / (1 + x²) on [0, 1], whose exact integral equals π/4. For an even n, compute midpoint, trapezoidal, and Simpson’s approximations and compare their absolute errors.
Interpretation
Observe how the Simpson approximation converges faster to π/4 as n increases, compared with the midpoint and trapezoidal rules on this smooth test function.