I'm trying to find formulas for the finite difference approximation "Five-points-stencil" of the first derivative for non-constant grid spacing. It's needed for the outermost left and right points. I tried to search for it but can't find it.
1 Answer
Given pairwise distinct real numbers $x_0,\dots,x_4$, one can approximate $f'(x_0)$ by a linear combination $a_0f(x_0)+\cdots+a_4f(x_4)$ so that $$g_j'(x_0)=a_0g_j(x_0)+\cdots+a_4g_j(x_4)$$ for $g_j(x):=x^j$ and $j\in\{0,\dots,4\}$.
Solving the resulting system of equations for $a_0,\dots,a_4$, we get $$a_0=-(a_1+\cdots+a_4)$$ and $$a_i=\frac{\prod\limits_{j\in\{0,\dots,4\}\setminus\{0,i\}}(x_0-x_j)} {\prod\limits_{j\in\{0,\dots,4\}\setminus\{i\}}(x_i-x_j)}$$ for $i\in\{1,\dots,4\}$.
(Here it does not matter whether $x_0$ is an outermost point or not.)