The well-known equation $$u''(x)= \frac{u(x+h) - 2 u(x) + u(x-h)}{h^2}+\mathcal{O}(h^2)$$ is derived by adding $$u(x+h)= u(x)+u'(x)h+\frac{1}{2}u''(x)h^2+\mathcal{O}(h^2)$$ $$u(x-h)= u(x)-u'(x)h+\frac{1}{2}u''(x)h^2+\mathcal{O}(h^2)$$
How does it look like if we have different step sizes such as $$u(x+h_1)= u(x)+u'(x)h_1+\frac{1}{2}u''(x)h_1^2+\mathcal{O}(h_1^2)$$ $$u(x-h_2)= u(x)-u'(x)h_2+\frac{1}{2}u''(x)h_2^2+\mathcal{O}(h_2^2)$$
Here, the first order derivatives do not cancel out each other. How can we define a good approximation for the second derivative in that case?
The motivation for this are linear constraints in an optimization problem where I optimize function values $u_i$ at points $x_i$. The function is supposed to be convex and I enforce this (very roughly) by constraints of the form $u_{i+1} - 2u_i + u_{i-1} > 0$. But this of course makes only sense if the spacing between the points is the same.
You make them cancel each other, taking the appropriate linear combination $$ h_2u(x+h_1)+h_1u(x-h_2)=... $$ The resulting terms with $u(x)$ need to be transported to the left side afterwards.