7
$\begingroup$

This may be a trivial question, but I've always wondered...

For the classical, central finite difference schemes, if I'm interested in determining the second derivative, does applying the first derivative scheme recursively (2x) give the same answer as performing the second derivative scheme once? What about the behavior of the truncation error?

I'm wondering if I should code a first-central FD and just call it recursively, or have a second-central FD separately to handle second derivatives. What are the differences and why choose one approach over the other?

The link I provided should help clarify my question.

EDIT: I'll be more explicit. If I go to the link above, I can choose a 3-point stencil which evaluates at $x_{i-1},x_0,x_{i+1}$. I have two options to calculate a second derivative.

Option 1: choose a first derivative central scheme, second order accurate, with coefficents $\{-1/2,0,1/2\}$. If I apply this recursively, I obtain the second derivative.

Option 2: choose a second derivative central scheme, second order accurate, with coefficients $\{1,-2,1\}$. I only have to apply this once to obtain the second derivative.

In the end, are they the same? I suspect the truncation errors are different, but I'm not sure.

$\endgroup$
  • $\begingroup$ A short note, if you do a "central" difference of a forward difference $u_x \approx \Delta x^{-1}\delta_+u_i := \Delta x^{-1}(u_{i+1} - u_i)$ and a backwards difference $u_x \approx \Delta x^{-1}\delta_-u_i := \Delta x^{-1}(u_{i} - u_{i-1})$, (so $u_{xx} \approx \Delta x^{-2} (\delta_+u_i - \delta_- u_i)$)you get the familiar second difference $\delta^2_x u_i = u_{i-1} - 2u_i + u_{i+1}$. I think using central difference twice would lead to the same, but over a larger stencil, so $u_{xx} \approx (2\Delta x)^{-2}(u_{i+2} - 2u_i + u_{i-2})$. $\endgroup$ – Steve Feb 25 '16 at 11:13
  • $\begingroup$ @Steve That's what I've also noticed. The stencil becomes larger. I think it gives the same answer, but I'm really curious if the truncation error changes...I suspect that it does. $\endgroup$ – ThatsRightJack Feb 25 '16 at 21:32
  • $\begingroup$ The order or truncation should be the same, $\mathcal{O}(\Delta x^2)$, but will be 4 times larger $\endgroup$ – Steve Feb 25 '16 at 23:08
  • $\begingroup$ @Steve I see you already showed that in your first comment (4 times larger) but I didn't catch it at first, sorry. That too is what I got in my initial investigation (4 times larger), but wasn't sure what to make of it. That's why I wanted people to pay attention to the truncation error. You have confirmed my suspicion. Why don't you copy your comment to an answer and maybe shed a little light on the impact of 4x larger truncation error and I'll accept the answer. Thanks for your insight. $\endgroup$ – ThatsRightJack Feb 25 '16 at 23:28
  • $\begingroup$ I think @GoHokies answer is pretty much the same as this if you replace every occurrence of $\delta x$ with $2\delta x$, especially since the order or the truncation error doesn't change. I'd go ahead an accept that, but I'll explicitly put in the leading error term for you $\endgroup$ – Steve Feb 26 '16 at 0:26
4
$\begingroup$

Short answer: yes (in exact arithmetic).

You'll have to use the centered difference formula evaluated at $x \pm \frac{1}{2}\delta x$, like this:

$$ u_x = \frac{u(x + \frac{1}{2}\delta x) - u(x - \frac{1}{2}\delta x)}{\delta x} + {\cal O}(\delta x^2) $$

Then, applying the formula recursively, you arrive at the "standard" second order finite-difference stencil:

\begin{eqnarray} u^{\rm FD}_{xx} &=& \frac{u_x(x + \frac{1}{2}\delta x) - u_x(x - \frac{1}{2}\delta x)}{\delta x} \\ &=& ... \\ &=& \frac{u(x + \delta x) - 2 u(x) + u(x - \delta x)}{(\delta x)^2} \\ &=& u_{xx} + \frac{(\delta x)^2}{12}u_{xxxx} + \text{higher order terms.} \end{eqnarray}

This recursive "trick" works with other finite-difference formulas as well.

However, I (for one) would not implement such a scheme recursively. The computational cost (defined as the total FLOP count) of evaluating a second derivative through the recursive scheme is higher than that of the "classic" formula, with no extra benefit to accuracy.

If you use $u(x+\delta x)$ and $u(x - \delta x)$, this is equivalent to the standard second derivative approximation but with twice the grid-width, hence the leading error term will be $\frac{(2\delta x)^2}{12}u_{xxxx}$, 4 times larger that above.

$\endgroup$
  • $\begingroup$ I appreciate your feedback and you are correct. But you've slightly side stepped my question. I'll edit my question to try and make it more clear. Basically, you have to evaluate at +/- 1dx for both cases. Not the half step. $\endgroup$ – ThatsRightJack Feb 25 '16 at 21:15
  • $\begingroup$ I do agree about the computational cost comment. I only raised this question out of curiosity. Also, I think Steve's comment above is in line with what I've noticed, but I'm not sure about the truncation error. $\endgroup$ – ThatsRightJack Feb 25 '16 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.