labs / lab-c-taylor-expansion
Next task →
Practical Labs/Lab: Taylor Expansion and Local Approximation
Level 2 · calculus

Lab: Taylor Expansion and Local Approximation

Build a minimal, verifiable implementation that demonstrates Taylor Expansion and Local Approximation. Connect the code to the governing equation, inspect its output numerically, and explain one failure case.

Mathematical basis

For Taylor Expansion and Local Approximation, verify f′(x)=lim⁡h→0(f(x+h)−f(x−h))/(2h)f'(x)=\lim_{h\to0}(f(x+h)-f(x-h))/(2h) and estimate the truncation error O(h2)O(h^2).

Instructions

  1. 01Read section 7 of the Taylor Expansion and Local Approximation learning page and write its governing equation on paper.
  2. 02Implement the core operation in JAX / NumPy on the Rosenbrock function and toy curves. Do not call a library function that solves the whole task.
  3. 03Verify the implementation on a hand-computed three-element or 3×3 example before scaling up.
  4. 04Run the experiment with the step size h and record gradient-check error.
  5. 05Inspect the output, identify one discrepancy with the theory, and write a one-paragraph explanation.

Starter code

import numpy as np

def central(f, x, h=1e-4):
    return (f(x + h) - f(x - h)) / (2*h)

f = lambda x: x**2 + 3*x
d = central(f, 2.0)
assert abs(d - 7.0) < 1e-6, d
print(d)