Numerical calculus lab
Download the complete lab archive. Python 3.10+ and its standard library are sufficient. Extract it and open a terminal in the calculus-foundations directory. On Windows use py -3 in place of python3.
python3 check.py starter
The initial NotImplementedError is intentional. Implement central_difference, trapezoid and bisect_root, preserving the documented domain and failure contracts. Begin with hand calculations: derivative of x² at 2, a single trapezoid for x² on [0,1], and two bisection steps for x²−2 on [1,2]. Predict results before running code.
python3 run.py starter > results.json
- Compare the derivative of exp(x) at x=1 against exp(1) as h shrinks. Identify a useful range and any cancellation region in your actual output; do not invent a strictly decreasing curve.
- Explain why trapezoid errors for x² approach a ratio of 4 when n doubles. Compare with the analytic bound 1/(6n²).
- For the exponential density with rate 2 on [0,5], keep quadrature error and omitted mass exp(−10) separate. The output includes both an exact retained mass and a conservative bound.
- Exercise invalid arguments, nonfinite callbacks, an invalid root bracket and an exhausted iteration budget. Explain why continuity cannot be tested by this checker.
After your attempt, run python3 check.py reference and compare implementations. Passing checks is necessary evidence, not proof of the theorems. Reproduce from a fresh extraction, retain the output and finish the project. The lab and project together have a 16–24 hour allowance; the project reuses these experiments.