I was asked to give a finite difference scheme to approximate the second derivative ${U''}$ on a random grid $(x_{i+1}-x_i = h_i$ and $x_i-x_{i-1} = h_{i-1})$ and give its order.
As usual for this kind of exercice I try to write the Taylor series devellopement for the $u(x_{i+1})$ and $u(x_{i-1})$ and find a linear combination that in this case would give the second derivative. However as the grid is random I'm kinda not sure If I could define it as a function of the paces $h_i$ and $h_{i-1}$ and divide it with so (I think it would pose any trouble) as I do here:
$(i)$ $u(x_{i+1}) = u(x_{i}) +h_i u'(x_i) + \frac{h_i ^2}{2}u''(x_i) + ... $
$(ii)$ $u(x_{i-1}) = u(x_{i}) - h_{i-1} u'(x_i) + \frac{h_{i-1} ^2}{2}u''(x_i) + ... $
doing $(i)/h_i - (ii)/h_{i-1}$ gives
$...$
$\frac{1}{h_ih_{i-1}}[h_{i-1}u(x_{i+1}) - h_iu(x_{i-1})-u(x_i)(h_{i-1}-h_i)] + cst_1h_i^2u'''(x_i) + cst_2h_{i-1}^2u'''(x_i) + ... = \frac{1}{2}(h_i-h_{i-1})u''(x_i)$
which gives
$u''(x_i) ≈ 2\frac{1}{h_i-h_{i-1}}\frac{1}{h_ih_{i-1}}[h_{i-1}u(x_{i+1}) - h_iu(x_{i-1})-u(x_i)(h_{i-1}-h_i)]$
with and $error$ of second order $O(h^2)$