I need to derive three discretizations, and present them as stencils. I already found one:
$\frac{\frac{\partial u}{\partial y}u_{i+1,j}-\frac{\partial u}{\partial y}u_{i-1,j}}{2h}$
$\frac{u_{i+1,j+1}-u_{i+1,j-1}-u_{i-1,j+1}+u_{i+1,j+1}}{4h^2}$
so the stencil is:$\frac{1}{4h^2}\begin{bmatrix} -1 & 0&1 \\ 0&0&0 \\ 1&0&-1\\ \end{bmatrix}$.
Can someone help me on how to derive the two?
Some notation first: $u_{i,j}$ denotes the function at place $(i,j)$. The superscript denotes the derivatives ie $\frac{\partial}{\partial x} u = u^x$
We will first Taylor expand all the terms in the stencil around $u_{i,j}$.
$$u_{i,j} = u_{i,j} \\ u_{i \pm1, j} = u_{i,j} + (\pm h)u_{i,j}^x + \frac{h^2}{2}u_{i,j}^{xx} \\ u_{i, j \pm 1} = u_{i,j} + (\pm h)u_{i,j}^y + \frac{h^2}{2} u_{i,j}^{yy}\\ u_{i \pm1, j \pm 1} = u_{i,j} + (\pm h)u_{i,j}^y + (\pm h)u_{i,j}^x + \frac{h^2}{2}(u_{i,j}^{xx} + (\pm)(\pm)2 u_{i,j}^{xy} + u_{i,j}^{yy})$$
Where, the sign in front of $u_{i,j}^{xy}$ depends both on $\pm$ in $i$ and in $j$.
Now, somewhat bruteforce-ish, we will approximate $u_{i,j}^{xy}$ by the sum of terms above, with weights given by the stencil in question.
$u_{i,j}^{xy} \approx \frac{1}{h^2}\big(a_1 u_{i,j} + a_2 (u_{i-1,j}+u_{i+1,j}+u_{i,j-1}+u_{i,j+1}) + a_3 (u_{i-1,j+1}+u_{i+1,j-1})\big)$
Rewriting (plugging in the expressions of Taylor expansion gives, and rearranging the equation in terms of different derivatives)
$$ a_1 + 4a_2 + 2a_3 = 0 \text{ eliminating } u_{i,j} \\ 2a_2 + 2a_3 = 0 \text{ eliminating } u_{i,j}^{xx} \\ 2a_2 + 2a_3 = 0 \text{ eliminating } u_{i,j}^{yy} \\ -a_3 = 1 \text{ preserving } u_{i,j}^{xy} \\ $$
Observe that in our case $u_{i,j}^{x}$ term is eliminated for all values of $a_2, a_3$ the same for $u_{i,j}^{y}$.
Solving the equations gives: $a_3 = -1, a_2 = 1, a_1 = -2$ and thus the stencil.
The second form can be done in similar fashion - the last equation will now read $a_3 =1$.
Likewise, the last stencil can be done as well by writing out the equation and grouping the terms by derivatives.