TME 310 - Computational Physical Modeling
University of Washington Tacoma
What is a derivative?
A function or value that describes
In calculus, we learned how to find derivatives analytically.
In this course, we’ll approximate derivatives numerically
The definition of a derivative:
\[f'(x) = \lim_{dx \to 0} \frac{f(x + dx) - f(x)}{dx}\]






If we evaluate a function at intervals spaced at \(dx\), we are essentially converting our continuous function into a set of discrete data points.


We discretize functions every time we plot them

We discretize functions every time we plot them

Let’s apply these concepts to finding numerical derivatives using three simple approaches:
In the forward finite difference (FFD) method, from a given pair of points, \((x_i,y_i)\), we approximate the derivative by looking “forward” to the next pair of points, \((x_{i+1},y_{i+1})\)
\[ \left[\frac{dy}{dx}\right]_i = \frac{y_{i+1} - y_i}{x_{i+1} - x_i}\]


\((t_0, x_0, y_0)\)
\((t_1, x_1, y_1)\)
\((t_2, x_2, y_2)\)
\((t_n, x_n, y_n)\)







As we step through the FFD, two problems are apparent:
For a dataset with \(n\) points, FFD will give us \(n-1\) estimates of the derivative.
Let’s address issue 2 first
In the central finite difference (CFD) method, from a given pair of points, \((x_i,y_i)\), we approximate the derivative by looking at the two pairs of points on either side: \((x_{i-1},y_{i-1})\) and \((x_{i+1},y_{i+1})\)
\[ \left[\frac{dy}{dx}\right]_i = \frac{y_{i+1} - y_{i-1}}{x_{i+1} - x_{i-1}}\]





The central finite difference seems to
But it has an even more limited range than the forward finite difference method:
For a dataset with \(n\) points, CFD will give us \(n-2\) estimates of the derivative.
Solution: use CFD wherever possible, use FFD when needed
That still leaves us with \(n-1\) estimates…
Enter the backward finite difference method
In the backward finite difference (BFD) method, from a given pair of points, \((x_i,y_i)\), we approximate the derivative by looking “backward” at the previous pair of points, \((x_{i-1},y_{i-1})\)
\[ \left[\frac{dy}{dx}\right]_i = \frac{y_{i} - y_{i-1}}{x_{i} - x_{i-1}}\]


Because it has the least error, the central finite difference method should be used wherever possible.



Numpy has a function for discrete differentiation: numpy.gradient
