finite_differences
Approximate first and second derivatives of f(x) at a point using forward, backward, and central finite differences, then compare them with exact SymPy derivatives and errors.
Instructions
Approximate the first and second derivatives of f(x) at x with finite differences.
Computes forward, backward and central differences for the first derivative, plus the central second derivative, and compares each against the exact derivative from SymPy.
Args: func_str: Math expression in x. x_val: Point where the derivative is evaluated. h: Step size (small, positive). precision: Rounding digits. plot: When True, also return a PNG of f(x) and its exact tangent.
Returns:
Dict with the exact and numerical derivatives and their errors. With
plot=True a list [dict, Image] is returned instead.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| h | No | ||
| plot | No | ||
| x_val | Yes | ||
| func_str | Yes | ||
| precision | No |