18. Finite Differences - First Derivative#

18.1. Forward differencing#

\[\begin{split} \begin{aligned} f\left(x_0+h\right)&= f\left(x_0\right)+ hf^{\prime}\left(x_0\right)+ \frac{h^2}{2!}f^{\prime\prime}\left(x_0\right)+ \cdots+ \frac{h^n}{n!}f^{\left(n\right)}\left(x_0\right)+ \cdots\\ f^{\prime}\left(x_0\right)&= \dfrac{f\left(x_0+h\right)-f\left(x_0\right)}{h}- \left( \dfrac{h}{2!} f^{\prime\prime}\left(x_0\right)+ \dfrac{h^{2}}{3!} f^{\prime\prime\prime}\left(x_0\right)+ \cdots+ \dfrac{h^{n-1}}{n!} f^{\left(n\right)}\left(x_0\right)+ \cdots \right) \\ f^{\prime}\left(x_0\right)&= \dfrac{f\left(x_0+h\right)-f\left(x_0\right)}{h}+ \mathcal{O}\left(h\right) \end{aligned} \end{split}\]

18.2. Backward differencing#

\[\begin{split} \begin{aligned} f\left(x_0-h\right)&= f\left(x_0\right)- hf^{\prime}\left(x_0\right)+ \frac{h^2}{2!}f^{\prime\prime}\left(x_0\right)- \cdots+ {\left(-1\right)}^{n} \frac{h^n}{n!}f^{\left(n\right)}\left(x_0\right)+ \cdots\\ f^{\prime}\left(x_0\right)&= \dfrac{f\left(x_0\right)-f\left(x_0-h\right)}{h}+ \left( \dfrac{h}{2!} f^{\prime\prime}\left(x_0\right)+ \dfrac{h^{2}}{3!} f^{\prime\prime\prime}\left(x_0\right)+ \cdots+ {\left(-1\right)}^{n} \dfrac{h^{n-1}}{n!} f^{\left(n\right)}\left(x_0\right)+ \cdots \right)\\ f^{\prime}\left(x_0\right)&= \dfrac{f\left(x_0\right)-f\left(x_0-h\right)}{h}+ \mathcal{O}\left(h\right) \end{aligned} \end{split}\]

18.3. Arriving at Central difference#

\[\begin{split} \begin{aligned} f\left(x_0+h\right)&= f\left(x_0\right)+ hf^{\prime}\left(x_0\right)+ \frac{h^2}{2!}f^{\prime\prime}\left(x_0\right)+ \cdots+ \frac{h^n}{n!}f^{\left(n\right)}\left(x_0\right)+ \cdots\\ f\left(x_0-h\right)&= f\left(x_0\right)- hf^{\prime}\left(x_0\right)+ \frac{h^2}{2!}f^{\prime\prime}\left(x_0\right)- \cdots+ {\left(-1\right)}^{n} \frac{h^n}{n!}f^{\left(n\right)}\left(x_0\right)+ \cdots\\ f^{\prime}\left(x_0\right)&= \dfrac{f\left(x_0+h\right)-f\left(x_0-h\right)}{2h}- \left( \dfrac{h^{2}}{3!} f^{\prime\prime\prime}\left(x_0\right)+ \cdots+ \dfrac{h^{n-1}}{n!} f^{\left(n\right)}\left(x_0\right)+ \cdots \right)\\ f^{\prime}\left(x_0\right)&= \dfrac{f\left(x_0+h\right)-f\left(x_0-h\right)}{2h}+ \mathcal{O}\left(h^{2}\right) \end{aligned} \end{split}\]

19. Polynomial derivative estimation#

import matplotlib.pyplot as plt
import numpy as np
from numpy.polynomial import Polynomial
p = Polynomial(coef=[9, -3, 7, -4])
p_prime = p.deriv()
p_prime(0)
np.float64(-3.0)
plt.plot(*p.linspace(), lw=0.5);
../_images/bdce7b1cdf4ced3e06fc525dee233dbde9638eb819d3486750d650990a2eb832.png