# second derivative with non-uniform spacing

I am trying to derive the formula for the second-order second derivative of the function $f(z)$ in the case of non-uniform spacings.

I start by considering that, around $z=\zeta_k$:

$$f(z)=f(\zeta_k)+(z-\zeta_k)~f'(\zeta_k)+\frac{(z-\zeta_k)^2}{2!}f''(\zeta_k)+O((z-\zeta_k)^3)$$

where the primes indicate a differentiation with respect to $z$.

Then, I evaluate this formula at $\zeta_{k-1}$ and $\zeta_{k+1}$ and take the difference of the two to have an expression for $f''(\zeta_{k})$:

$$f(\zeta_{k-1}) = f(\zeta_{k-1})+ (\zeta_{k-1}-\zeta_{k})~f'(\zeta_{k})+\frac{(\zeta_{k-1}-\zeta_{k})^2}{2}f''(\zeta_{k})$$

$$f(\zeta_{k+1}) = f(\zeta_{k-1})+ (\zeta_{k+1}-\zeta_{k})~f'(\zeta_{k})+\frac{(\zeta_{k+1}-\zeta_{k})^2}{2}f''(\zeta_{k})$$

$$f''(\zeta_{k}) = 2\frac{f(\zeta_{k+1})-f(\zeta_{k-1})}{(\zeta_{k+1}-\zeta_{k})^2 (\zeta_{k-1}-\zeta_{k})^2} +2\frac{\mathbf{f'(\zeta_k)}\cdot(\zeta_{k+1}-\zeta_{k})(\zeta_{k-1}-\zeta_{k})}{(\zeta_{k+1}-\zeta_{k})^2 (\zeta_{k-1}-\zeta_{k})^2}$$

But I am not sure now on how to get rid of the first derivative on the rhs of the last equation.

Should I use the Taylor expansion a the beginning to derive an expression for $f'(\zeta_k)$, by stopping at $O((z-\zeta_k)^2)$, to plug into my last equation?

The problem I see with this is that I would be mixing up two different levels of accurancy.

Is there another way of doing this?

• Note that you have a linear system for $f'(\zeta_{k})$ and $f''(\zeta_{k})$ – gammatester Apr 30 '18 at 9:26

Imagine, your function $f(x)$ can be written as a polynomial of 3rd order: $$f(x) = f_{0}L_0(x)+f_1L_1(x)+f_2L_2(x)+f_3L_3(x)+\epsilon(\xi)$$ Where $L_i$ are the Lagrange basis polynomials, and for some $\epsilon$ within the interval defined by the interpolation support.
The interpolation error $\epsilon$ is written as follows: $$\epsilon(\xi) = \frac{\prod_{i=0}^{3}{(x_i-\xi)}}{4!}f^{4)}(\xi)$$ If the function $f(x)$ is smooth enough the error is of the order of $\epsilon\sim \bar{h}^4$, where $\bar{h}$ is a kind of average of the spacings.
While computing the second derivative of $f(x)$ we'll find that the error is of the order of $\epsilon''(\xi)\sim \bar{h}^2$, as desired.