## Taylor Series $ f(x + h) = f(x) + f'(x)h + f''(x) \frac{h^{2}}{2!} + \dots + f^{(n)}(x) \frac{h^{n}}{n!} + \dots $ ## Basic Finite Differences ![[Pasted image 20250410010844.png|350]] ### First Derivative Finite Differences | Scheme | Formula | Order of Accuracy | Notes | | -------- | ------------------------------------------ | ----------------- | ------------------------------- | | Forward | $f'(x) \approx \frac{f(x+h) - f(x)}{h}$ | First-order | Uses point ahead: $x+h$ | | Backward | $f'(x) \approx \frac{f(x) - f(x-h)}{h}$ | First-order | Uses point behind: $x-h$ | | Centered | $f'(x) \approx \frac{f(x+h) - f(x-h)}{2h}$ | Second-order | Uses points symmetric about $x$ | ### Second Derivative Finite Differences | Scheme | Formula | Order of Accuracy | Notes | | -------- | ----------------------------------------------------- | ----------------- | ------------------------------------------------- | | Forward | $f''(x) \approx \frac{f(x+2h) - 2f(x+h) + f(x)}{h^2}$ | 1st-order | Uses $x$, $x+h$, $x+2h$ | | Backward | $f''(x) \approx \frac{f(x) - 2f(x-h) + f(x-2h)}{h^2}$ | 1st-order | Uses $x$, $x-h$, $x-2h$ | | Centered | $f''(x) \approx \frac{f(x+h) - 2f(x) + f(x-h)}{h^2}$ | 2nd-order | Symmetric, more accurate, default in interior use | ## Higher Order Finite Differences ### Taylor Table Method to systematically derive finite difference formulas with a desired order of accuracy for approximating derivatives | Scheme | Formula | Order of Accuracy | Stencil Width | | -------- | ------------------------------------------------------------------ | ----------------- | ------------- | | Forward | $\frac{-3f(x_i) + 4f(x_{i+1}) - f(x_{i+2})}{2h}$ | 2nd | 3 | | Forward | $\frac{-11f(x_i) + 18f(x_{i+1}) - 9f(x_{i+2}) + 2f(x_{i+3})}{6h}$ | 3rd | 4 | | Backward | $\frac{3f(x_i) - 4f(x_{i-1}) + f(x_{i-2})}{2h}$ | 2nd | 3 | | Backward | $\frac{11f(x_i) - 18f(x_{i-1}) + 9f(x_{i-2}) - 2f(x_{i-3})}{6h}$ | 3rd | 4 | | Centered | $\frac{-f(x_{i+2}) + 8f(x_{i+1}) - 8f(x_{i-1}) + f(x_{i-2})}{12h}$ | 4th | 5 | Ex. Approximate $\frac{\partial u}{\partial x} \big|_{j}$ using a centered 3-point stencil: $ \frac{\partial u}{\partial x}\bigg|_j \approx a u_{j-1} + b u_j + c u_{j+1} $ Use Taylor series to expand $u_{j-1}$, $u_j$, and $u_{j+1}$ about point $j$: | Term | $u_j$ | $\Delta x \cdot u_j'$ | $\Delta x^2 \cdot u_j''$ | $\Delta x^3 \cdot u_j'''$ | $\Delta x^4 \cdot u_j^{(4)}$ | $\Delta x^5 \cdot u_j^{(5)}$ | | ------------------------------------------------ | ----------- | ---------------------- | ------------------------ | ------------------------- | ---------------------------- | ---------------------------- | | $a u_{j-1}$ | $a$ | $a \cdot \frac{-1}{1}$ | $a \cdot \frac{1}{2}$ | $a \cdot \frac{-1}{6}$ | $a \cdot \frac{1}{24}$ | $a \cdot \frac{-1}{120}$ | | $b u_j$ | $b$ | $0$ | $0$ | $0$ | $0$ | $0$ | | $c u_{j+1}$ | $c$ | $c \cdot \frac{1}{1}$ | $c \cdot \frac{1}{2}$ | $c \cdot \frac{1}{6}$ | $c \cdot \frac{1}{24}$ | $c \cdot \frac{1}{120}$ | Choose $a$, $b$, $c$ so the coefficient of $u_j'$ is $1$ and other terms vanish up to the desired order. The first term that doesn't vanish is the truncation error. ### Padé Schemes (Compact FD) Pade schemes are generally of the following form: $ d\left( \frac{ \partial u }{ \partial x } \right)_{j-1} + \left( \frac{ \partial u }{ \partial x } \right)_{j}+e\left( \frac{ \partial u }{ \partial x } \right)_{j+1} - \frac{1}{\Delta x}(au_{j-1}+bu_{j}+cu_{j+1}) = ? $ Here are some common ones: | Scheme | Equation | Order of Accuracy | Stencil Width | | ------------ | -------------------------------------------------------------------------------------------------------------------------- | ----------------- | ------------- | | Centered | $\frac{1}{4} f'_{i-1} + f'_i + \frac{1}{4} f'_{i+1} = \frac{3}{4h}(f_{i+1} - f_{i-1})$ | 4th | 3 | | Higher order | $\frac{1}{3} f'_{i-1} + f'_i + \frac{1}{3} f'_{i+1} = \frac{14}{9h}(f_{i+1} - f_{i-1}) + \frac{1}{36h}(f_{i-2} - f_{i+2})$ | 6th | 5 | | Forward | $f'_i + 2f'_{i+1} = \frac{-5f_i + 4f_{i+1} + f_{i+2}}{h}$ | 2nd | 3 | | Backward | $f'_i + 2f'_{i-1} = \frac{5f_i - 4f_{i-1} - f_{i-2}}{h}$ | 2nd | 3 | The derivatives are unknown and must be determined implictly by solving a tridiagonal system of linear equations: $ \begin{bmatrix} 1 & e & 0 & ⋯ & 0 \\ d & 1 & e & ⋯ & 0 \\ 0 & d & 1 & ⋯ & 0 \\ ⋮ & ⋮ & ⋮ & ⋱ & e \\ 0 & ⋯ & 0 & d & 1 \end{bmatrix} \begin{bmatrix} f_{1}' \\ f_{2}' \\ ⋮ \\ f_{n}' \end{bmatrix}-\frac{1}{\Delta x}\begin{bmatrix} b & c & 0 & ⋯ & 0 \\ a & b & c & ⋯ & 0 \\ 0 & a & b & ⋯ & 0 \\ ⋮ & ⋮ & ⋮ & ⋱ & c \\ 0 & ⋯ & 0 & a & b \end{bmatrix}\begin{bmatrix} u_{1} \\ u_{2} \\ ⋮ \\ u_{n} \end{bmatrix}=0 $ The schemes can be derived similarly to taylor tables by taking the taylor expansion of each unknown and solving for the coefficients $a$, $b$, $c$, $d$, and $e$. | | $u_j$ | $\Delta x \left( \frac{\partial u}{\partial x} \right)_j$ | $\Delta x^2 \left( \frac{\partial^2 u}{\partial x^2} \right)_j$ | $\Delta x^3 \left( \frac{\partial^3 u}{\partial x^3} \right)_j$ | $\Delta x^4 \left( \frac{\partial^4 u}{\partial x^4} \right)_j$ | $\Delta x^5 \left( \frac{\partial^5 u}{\partial x^5} \right)_j$ | | --------------------------------------------------------------- | ----- | --------------------------------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------- | | $\Delta x d \left( \frac{\partial u}{\partial x} \right)_{j-1}$ | | $d$ | $d \cdot \frac{-1}{1}$ | $d \cdot \frac{(-1)^2}{2}$ | $d \cdot \frac{(-1)^3}{6}$ | $d \cdot \frac{(-1)^4}{24}$ | | $\Delta x \left( \frac{\partial u}{\partial x} \right)_j$ | | $1$ | | | | | | $\Delta x e \left( \frac{\partial u}{\partial x} \right)_{j+1}$ | | $e$ | $e \cdot \frac{1}{1}$ | $e \cdot \frac{1^2}{2}$ | $e \cdot \frac{1^3}{6}$ | $e \cdot \frac{1^4}{24}$ | | $-a u_{j-1}$ | $-a$ | $-a \cdot \frac{-1}{1}$ | $-a \cdot \frac{(-1)^2}{2}$ | $-a \cdot \frac{(-1)^3}{6}$ | $-a \cdot \frac{(-1)^4}{24}$ | $-a \cdot \frac{(-1)^5}{120}$ | | $-b u_j$ | $-b$ | | | | | | | $-c u_{j+1}$ | $-c$ | $-c \cdot \frac{1}{1}$ | $-c \cdot \frac{1^2}{2}$ | $-c \cdot \frac{1^3}{6}$ | $-c \cdot \frac{1^4}{24}$ | $-c \cdot \frac{1^5}{120}$ | ## Nonuniform Grids - Nonuniform grids have variable spacing: $h_i = x_i - x_{i-1}$ is not constant. - Standard FD formulas (assuming uniform $h$) are not valid. - You must derive new formulas using actual spacings via Taylor expansions. ### First Derivative (Centered, 3-Point Nonuniform) Let: - $h_- = x_i - x_{i-1}$ - $h_+ = x_{i+1} - x_i$ Then: $ f'(x_i) \approx \frac{-h_+^2 f_{i-1} + (h_+^2 - h_-^2) f_i + h_-^2 f_{i+1}}{h_- h_+ (h_- + h_+)} $ - This is a second-order accurate scheme for arbitrary spacing. - For higher-order accuracy, use larger stencils and solve via Taylor expansions.