Part 3: Deriving numerical derivatives from Taylor series expansions

Part 3: Deriving numerical derivatives from Taylor series expansions#

After we had a closer look at the meaning of Taylor series, you will now practice how you can apply Taylor series to derive expressions for numerical derivatives.

Task 3.1

Derive the backward difference method such that it is second-order accurate. Refer to the book for an illustration of this approach with first-order accuracy. Insert an image of your math below.

You don’t have to further use the result in this assignment, but it is useful to understand the approach and prepare for the exam.

Tips:

  • You will have to combine Taylor series expansions for the function at two different points.

  • At what order do you need to truncate the Taylor series to get a second order accurate method?

Solution 3.1

For backward differences we evaluate the Taylor series around \(x_i\) at \(x_{i−1}\) and \(x_{i−2}\). To end up with a second-order accurate expression, we need to include terms at least up to \(n=2\). This yields the following Taylor approximations:

\[f(x_{i-1})\approx f(x_{i})+(x_{i-1}-x_i)\frac{\partial f(x_{i})}{\partial x} +\frac{(x_{i-1}-x_i)^2}{2}\frac{\partial^2 f(x_i)}{\partial x^2}+\mathcal{O}((x_{i-1}-x_i)^3)\]
\[f(x_{i-2})\approx f(x_{i})+(x_{i-2}-x_i)\frac{\partial f(x_{i})}{\partial x} +\frac{(x_{i-2}-x_i)^2}{2}\frac{\partial^2 f(x_i)}{\partial x^2}+\mathcal{O}((x_{i-2}-x_i)^3)\]

We set \(\Delta x = x_i - x_{i-1}\) for all \(i\), which also means: \(2\Delta x = x_i-x_{i-2}\)

\[f(x_{i-1})\approx f(x_{i})-\Delta x\frac{\partial f(x_{i})}{\partial x} +\frac{\Delta x^2}{2}\frac{\partial^2 f(x_i)}{\partial x^2}+\mathcal{O}(\Delta x^3)\]
\[f(x_{i-2})\approx f(x_{i})-2\Delta x\frac{\partial f(x_{i})}{\partial x} +\frac{4\Delta x^2}{2}\frac{\partial^2 f(x_i)}{\partial x^2}+\mathcal{O}(\Delta x^3)\]

To get rid of the term including the second derivative, we multiply the first expression by 4 and subtract the second expression:

\[\begin{split} \begin{aligned} 4f(x_{i-1})-f(x_{i-2})&\approx (4-1)f(x_{i})-(4-2)\Delta x\frac{\partial f(x_{i})}{\partial x} + (4-4)\frac{\Delta x^2}{2}\frac{\partial^2 f(x_i)}{\partial x^2}+\mathcal{O}(\Delta x^3)\\ &= 3f(x_{i})-2\Delta x\frac{\partial f(x_{i})}{\partial x} + \mathcal{O}(\Delta x^3) \end{aligned} \end{split}\]

Bring the derivative to the left side and all terms involving \(f(x)\) to the right side: $\( 2\Delta x\frac{\partial f(x_{i})}{\partial x} \approx 3f(x_i)-4f(x_{i-1})+f(x_{i-2}) +\mathcal{O}(\Delta x^3)\)$

Divide by \(2 \Delta x\):

\[\frac{\partial f(x_{i})}{\partial x} \approx \frac{3f(x_i)-4f(x_{i-1})+f(x_{i-2})}{2\Delta x} +\mathcal{O}(\Delta x^2)\]

Note how the order of the error changes because we divide by \(\Delta x\). The final expression is second-order accurate.

By Anna Störiko, Ronald Brinkgreve, Justin Pittman, Jaime Arriaga Garcia, Robert Lanzafame, Delft University of Technology. CC BY 4.0, more info on the Credits page of Workbook.