====== Math 753/852 Finite Differencing ====== The main things to know here are a few formulae for approximating derivatives using finite differences: === First derivative df/dx === Given a set of evenly space gridpoints $x_1, x_2, \ldots$, where $x_i = x_1 + (i-1) h$, and a function $y(x)$ evaluated at the gridpoints $y_1 = y(x_1), y_2 = y(x_2), \ldots$, we can approximate the first derivative of $y(x)$ at the gridpoints several ways **One-sided finite differencing for the first derivative**, rightwards \begin{equation*} \frac{dy}{dx}(x_i) = \frac{y_{i+1} - y_{i}}{h} + O(h) \end{equation*} **One-sided finite differencing for the first derivative**, leftwards \begin{equation*} \frac{dy}{dx}(x_i) = \frac{y_{i} - y_{i-1}}{h} + O(h) \end{equation*} **Centered finite differencing for the first derivative** \begin{equation*} \frac{dy}{dx}(x_i) = \frac{y_{i+1} - y_{i-1}}{2h} + O(h^2) \end{equation*} In practice you use the fraction on the right-hand-side as an approximation of the derivative, knowing that there is an $O(h)$ or $O(h^2)$ error in the approximation. === Second derivative === To approximate the second derivative $d^2y/dx^2$, we use the **Centered finite differencing for the second derivative** \begin{equation*} \frac{d^2y}{dx^2}(x_i) = \frac{y_{i+1} - 2 y_i + y_{i-1}}{h^2} + O(h^2) \end{equation*} === Other formulae === There are many, many other finite-difference formulae, for higher-order derivatives, higher-order accuracy, and different choices of which gridpoint values enter into the formula. As a starting point, see the following Further reading * [[https://en.wikipedia.org/wiki/Finite_difference|Finite Difference]] (wikipedia) * [[http://www.rsmas.miami.edu/personal/miskandarani/Courses/MSC321/lectfiniteDifference.pdf| Finite Differences lecture]] (Mohamed Iskandarani, University of Miami)