# When setting up 2nd order first derivative approximations in a finite differencing scheme, why are these equations equivalent?

In approximating a first derivative term (assuming $$\delta z$$ is the distance between two spatial grid points) using a finite differencing scheme I came up with these basic equations:

$$\phi \frac{\partial y}{\partial z} = \phi_z \left[ \frac{y_{z+\Delta z} - y_{z-\Delta z}}{2 \Delta z} \right]$$

$$\phi C_p \frac{\partial T}{\partial z} = \phi_z C_{p,z} \left[ \frac{T_{z+\Delta z} - T_{z-\Delta z}}{2 \Delta z} \right]$$

However it was commented to me that these equations are equivalent:

$$\phi \frac{\partial y}{\partial z} = \frac{1}{2} \left[ \phi_{z+\Delta z/2} \left( \frac{y_{z+\Delta z} - y_z}{\Delta z} \right) + \phi_{z-\Delta z/2} \left( \frac{y_z - y_{z-\Delta z}}{\Delta z} \right) \right]$$

$$\phi C_p \frac{\partial T}{\partial z} = \frac{1}{2} \left[ \phi_{z+\Delta z/2} C_{p,z+\Delta z/2} \left( \frac{T_{z+\Delta z} - T_z}{\Delta z} \right) + \phi_{z-\Delta z/2} C_{p,z-\Delta z/2} \left( \frac{T_z - T_{z-\Delta z}}{\Delta z} \right) \right]$$

My question is why are these the same? The algebra does not seem to simplify down easily such that they result in the same equations. How can it be the case that both equations are 2nd order finite difference approximations?

• "Equivalent" and "same" typically have different meanings/definitions. Can you clarify the source of someone commenting that the second pair is "equivalent"? Apr 15 at 12:52

For a general first-order, constant coefficient partial derivative with equal grid spacing, the central finite difference scheme is the same as the average of the forward and backward finite difference scheme, which is provable by simple algebra: $$\frac{\partial f}{\partial x}\approx\frac{f(x+\delta x)-f(x-\delta x)}{2\delta x}=\frac{1}{2}\left[\frac{f(x+\delta x)-f(x)}{\delta x}+\frac{f(x)-f(x-\delta x)}{\delta x}\right]. \tag{1}$$ As this assumes a constant coefficient (set to 1 in this case), it is different from your system.

For the variable coefficient PDE, you want to consider that the coefficient varies in the flux balance between $$[z-\delta z,\,z]$$ and $$[z,\,z+\delta z]$$. Your first pair of equations does not do this; instead, you've effectively assumed a constant coefficient system in deriving your finite difference scheme.

Now the second set of equations can also be derived from an averaging of a forward and backward scheme, but it considers also the flux balance of the coefficients: $$\kappa(x)\frac{\partial f}{\partial x}\approx\frac{1}{2}\left[g\left(x+\frac{1}{2}\delta x\right)+g\left(x-\frac{1}{2}\delta x\right)\right]\tag{2}$$ where $$g\left(x+\frac{1}{2}\delta x\right)=\kappa\left(x+\frac{1}{2}\delta x\right)\frac{f\left(x+\delta x\right)-f\left(x\right)}{\delta x}$$ is the forward difference and with a symmetric form for the backward difference, $$g(x-\delta x/2$$).

Hence, I would not say that the two are the same or are equivalent. The second set is clearly superior because it properly considers the flux balance of the coefficients when deriving the finite difference scheme.

• Thank you this is very clear now. Edit: Also, I see from your profile that you are interested in computational physics and fluid dynamics. By any chance do you code in Python? If so I would highly appreciate if you gave my question on the python forum a look if you have time: stackoverflow.com/questions/71968585/… Apr 22 at 20:17
• That question probably would be better suited here or over at Computational Science than over at StackOverflow. That said, you are looking for finite difference methods. You might be interested in this Wikipedia entry. For some resources, I mention a couple in this answer of mine. Apr 23 at 16:26
• Ideal thank you I will post repost that exact question on the computational science forum Apr 24 at 22:47
• Posted. Thank you! Apr 24 at 22:54

They are not the same, as in the first case the value of $$\phi$$ is taken at point $$z$$, whereas in the second case at intermediate points. Expanding functions $$y, \phi, T$$ in powers of $$\Delta z$$ will likely show that these equations produce the same result up to the first order in $$\Delta z$$... but differ in the order of $$\Delta z$$ where the corrections appear. I bet on the second form being more precise. Numerically this means that the second approximation would allow using larger steps $$\Delta z$$, since the corrections are smaller.

This is closely related to the difference between Euler discretization and Runge-Kutta methods.

• Thanks for the response. Are you saying that the first method is a second order Euler discretisation and the second method is a second order Runge Kutta discretisation, which are equivalent approaches but not the same past the first order? Apr 14 at 9:35
• @casualguitar I am not sure about the exact meaning of eurler and runge-kutta in this context, but this is the idea. Apr 14 at 12:49