Differential Equations
If we want to compute a numerical solution for the given problem we need to compute differential derivatives for each cell. These can be obtained by regarding the values of the neighboring cells.
In 2D however we need to keep the other direction static.
From Taylor we obtain the following equations for a cartesian grid:
\left(\frac{\delta \Phi}{\delta x} \right)_{i,j} = \frac{\Phi(x_{i+1},y_j) - \Phi_(x_{i-1},y_j)}{x_{i+1} - x_{i-1}} = \frac{\Phi(x_{i+1},y_j) - \Phi_(x_{i-1},y_j)}{2 \Delta x}
\left(\frac{\delta \Phi}{\delta y} \right)_{i,j} = \frac{\Phi(x_{i},y_{j+1}) - \Phi(x_{i},y_{j-1})}{y_{j+1} - y_{j-1}} = \frac{\Phi(x_{i},y_{j+1}) - \Phi(x_{i},y_{j-1})}{2 \Delta y}
\left( \frac{\delta^2 \Phi}{\delta x^2} \right)_{i,j} = \frac{\Phi(x_{i+1},y_j) - 2 \Phi(x_{i},y_j) + \Phi(x_{i-1},y_j) }{(x_{i+1} - x_{i}) \cdot (x_{i} - x_{i-1})} = \frac{\Phi(x_{i+1},y_j) - 2 \Phi(x_{i},y_j) + \Phi(x_{i-1},y_j) }{\Delta x^2}
\left( \frac{\delta^2 \Phi}{\delta y^2} \right)_{i,j} = \frac{\Phi(x_{i},y_{j+1}) - 2 \Phi(x_{i},y_{j}) + \Phi(x_{i},y_{j-1}) }{(y_{j+1} - y_{j}) \cdot (y_{j} - y_{j-1})} = \frac{\Phi(x_{i},y_{j+1}) - 2 \Phi(x_{i},y_{j}) + \Phi(x_{i},y_{j-1}) }{\Delta y^2}
One-Sided Derivatives
This works fine for inner cells, though for boundary cells we sometimes need to compute one-sided derivatives:
Derivation
Taylor of 2nd order:T_{f(x,a)} = \sum_{n=0}^{\infty} \frac{f^{n}(a)}{n!}(x-a)^n = f(a) + f'(a)(x-a) + \frac{f''(a)}{2}(x-a)^2 + ...
\Phi_{i, nY-1} = \Phi_{i, nY} + \left( \frac{\delta \Phi}{\delta \eta} \right)_{i,nY} \cdot (-\Delta \eta) + \frac{1}{2} \left( \frac{\delta^2 \Phi}{\delta \eta^2} \right)_{i,nY} \cdot (-\Delta \eta)^2
\Phi_{i, nY-2} = \Phi_{i, nY} + \left( \frac{\delta \Phi}{\delta \eta} \right)_{i,nY} \cdot (-2 \Delta \eta) + \frac{1}{2} \left( \frac{\delta^2 \Phi}{\delta \eta^2} \right)_{i,nY} \cdot (-2 \Delta \eta)^2
4 \Phi_{i, nY-1} - \Phi_{i, nY-2} = 4 \Phi_{i, nY} - \Phi_{i, nY} - 4 \left( \frac{\delta \Phi}{\delta \eta} \right)_{i,nY} \Delta \eta + 2 \left( \frac{\delta \Phi}{\delta \eta} \right)_{i,nY} \Delta \eta
\left( \frac{\delta \Phi}{\delta \eta} \right)_{i,nY} = \frac{\Phi_{i, nY-2} - 4 \Phi_{i, nY-1} + 3 \Phi_{i, nY} }{2 \Delta \eta}
\text{west: } \left( \frac{\delta \Phi}{\delta x} \right)_{i,j} = \frac{- \Phi(x_{i+2}) + 4 \Phi(x_{i+1}) - 3 \Phi(x_{i})}{2 \Delta x}
\text{east: } \left( \frac{\delta \Phi}{\delta x} \right)_{i,j} = \frac{\Phi(x_{i-2}) - 4 \Phi(x_{i-1}) + 3 \Phi(x_{i})}{2 \Delta x}
And respectively for y:
\text{north: } \left( \frac{\delta \Phi}{\delta y} \right)_{i,j} = \frac{- \Phi(y_{j+2}) + 4 \Phi(y_{j+1}) - 3 \Phi(y_{j})}{2 \Delta y}
\text{south: } \left( \frac{\delta \Phi}{\delta y} \right)_{i,j} = \frac{\Phi(y_{j-2}) - 4 \Phi(y_{j-1}) + 3 \Phi(y_{j})}{2 \Delta y}