# If analytically, a function is not differentiable at a point, does it make sense to write a finite difference code for the function at that point?

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,

• 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. – Kyle Mandli Sep 23 '20 at 15:01

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.