Lesson 16 of 18
Chain Rule
The Chain Rule
The chain rule handles derivatives of composed functions :
Examples
| , | ||
|---|---|---|
| , | ||
| , | ||
| , |
Numerical Chain Derivative
We can approximate the chain derivative numerically using the central difference formula applied to the composition:
This is just the standard central difference, but applied to the composed function :
double chain_deriv(double (*f)(double), double (*g)(double),
double x, double h) {
return (f(g(x + h)) - f(g(x - h))) / (2.0 * h);
}
Verification
For at :
- Analytic:
- Numerical with : should match to 4+ decimal places
Your Task
Implement double chain_deriv(f, g, x, h) using the central difference on the composition .
TCC compiler loading...
Loading...
Click "Run" to execute your code.