Lesson 11 of 15
Differentiability
Differentiability
The derivative formalizes the idea of instantaneous rate of change.
Definition
A function (f) is differentiable at (c) if the following limit exists:
Key Facts
- If (f) is differentiable at (c), then (f) is continuous at (c)
- The converse is false: (f(x) = |x|) is continuous at 0 but not differentiable there
Numerical Differentiation
We can approximate the derivative using a small (h):
def derivative(f, x, h=1e-8):
return (f(x + h) - f(x)) / h
A better approximation uses the central difference:
This is more accurate because it cancels the second-order error term.
Higher Derivatives
The second derivative can be approximated by:
Your Task
Implement:
derivative(f, x, h)-- central difference approximation: ((f(x+h) - f(x-h)) / (2h))second_derivative(f, x, h)-- second derivative approximation: ((f(x+h) - 2f(x) + f(x-h)) / h^2)is_differentiable(f, x, h)-- checks if left and right derivatives are approximately equal (within 0.01 of each other)
Pyodide loading...
Loading...
Click "Run" to execute your code.