1
$\begingroup$

What would happen if I wrote a finite-difference code evaluated at a point where the function isn't differentiable analytically?

I'm trying to think analytically vs numerically.

Thanks,

$\endgroup$
1
  • $\begingroup$ Just to clarify, you have a set of data points and you want to take the derivative of them? If so one way to derive the finite difference formulas is to use an interpolant the width of the stencil, in effect making the assumption that things are smooth, and taking the derivative of the resulting polynomial. $\endgroup$ Commented Sep 23, 2020 at 15:01

1 Answer 1

3
$\begingroup$

You lose convergence order, or in the worst case convergence altogether. You can try this out: Take $$ f(x) = \begin{cases} 0 & \text{if $x<0$} \\ x^2 & \text{if $x\ge 0$}.\end{cases} $$ The function is differentiable, but not twice differentiable at $x=0$. It's exact derivative is $f'(0)=0$. Now compute the (second-order) symmetric finite difference approximation of this function: $$ D_h^\pm f(0) = \frac{f(0+h)-f(0-h)}{h} = h. $$ So for $h\to 0$, you have that $D_h^\pm f(0) \to f'(0)$, but only at a rate of $O(h)$, not $O(h^2)$ as otherwise expected. So the fact that $f$ is not twice differentiable means that you just lost an order of convergence.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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