# finite difference for a second order ode

I saw in a code for discretization of something like $\frac{d^2T(x)}{d^2x}$ , ( $x = sin(\theta)$ ) tries

   !============== here are some defined variables
deltaTheta = pi/150
deltax(i) = cos(theta(i)) * deltaTheta
dx = 0.5*(deltax(i) + deltax(i+1))
dx1 = 0.5*(deltax(i-1)+ deltax(i))
!============== here is the discretization that I am talking about
... = ((T(i+1) - T(i))/dx - (T(i) - T(i-1))/dx1)/(0.5 *(dx + dx1))


this discretization was for non-boundary cites; what does this discretization called?

• Do you mean beyond being called the three point stencil? Or are you talking about the choice of grid points? Nov 10, 2017 at 16:16
• @origimbo What I don't understand are defining and usage of "dx" and "dx1" Nov 10, 2017 at 18:32
• The three points might have different separations. Nov 10, 2017 at 19:21

It is just the computation of the second derivative from three non-equidistant points. It is computed by first computing (an approximation of) the derivatives on each of the two intervals adjacent to point $i$ using $$\frac{T(i+1)-T(i)}{\Delta(i+1)}$$ and $$\frac{T(i)-T(i-1)}{\Delta(i)}$$ and then computing (an approximation of) the second derivative by taking a finite difference stencil with regard to the midpoints of the two intervals: $$\frac{ \frac{T(i+1)-T(i)}{\Delta(i+1)} - \frac{T(i)-T(i-1)}{\Delta(i)} }{\frac{\Delta(i+1)+\Delta(i)}{2}}$$ Here, $\Delta(i+1)=x(i+1)-x(i)$ and $\Delta(i)=x(i)-x(i-1)$ are the dx1 and dx terms in the formula of the code you're looking at.
I have no idea how this relates to the dx and dx1 variables -- these look wrong to me since they are not increments but averages of the deltax(i) which themselves are not deltas (differences) but point locations as far as I can see. I can't seem to see that this choice of variable names or expressions makes sense.