I need to find (approximate) the second derivative of a discrete function. Usually I would approximate the second derivative with
$$f''(x)\approx\frac{f(x+h)-2f(x)+f(x-h)}{h^2}\tag{1}$$
In my case, however, the $x$ values at which $f$ is known are distributed non-uniformly. So the "forward" $h$ and "backward" $h$ can be different $h_1\neq h_2$.
Intuitively I would go with something like
$$f''(x)\approx\frac{f(x+h_1)-2f(x)+f(x-h_2)}{h_1h_2}\tag{2}$$
but when I start from the forward and backward difference I end up with
$$f''(x)\approx\frac{\frac{f(x+h_1)-f(x)}{h_1}-\frac{f(x)-f(x-h_2)}{h_2}}{?}$$
and I don't know what to put in the quotient. I guess the arithmetic mean $\frac{h_1+h_2}{2}$ would be a good choice but that leads to
$$f''(x)\approx\frac{\frac{2h_2}{h_1+h_2}f(x+h_1)-2f(x)+\frac{2h_1}{h_1+h_2}f(x-h_2)}{h_1h_2}\tag{3}$$
which for $h_1=h_2$ simplifies to $(1)$ but is not the same as $(2)$.
Is $(2)$ or $(3)$ the right way to do this or is there another way?
I agree that (3) is correct. The reason is that it is easy to check that (3) gives the correct result if $f(x) = 1$, if $f(x) = x$, and with a bit more work if $f(x) = x^2$. Hence this also shows that (3) is indeed a solution of the linear equation system of the previous answer.