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,
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,
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.