title: Compact finite difference
text: # Compact finite difference
  
  The compact finite difference formulation, or Hermitian formulation, is a numerical method to compute finite difference approximations. Such approximations tend to be more accurate for their stencil size (i.e. their compactness) and, for hyperbolic problems, have favorable dispersive error and dissipative error properties when compared to explicit schemes. A disadvantage is that compact schemes are implicit and require to solve a diagonal matrix system for the evaluation of interpolations or derivatives at all grid points. Due to their excellent stability properties, compact schemes are a popular choice for use in higher-order numerical solvers for the Navier-Stokes Equations.
  
  ## Example
  
  The classical Pade scheme for the first derivative at a cell with index $i$ ($f'_{i}$) reads;
  
  ${\frac {1}{4}}f'_{i-1}+f'_{i}+{\frac {1}{4}}f'_{i+1}={\frac {3}{2}}{\frac {f_{i+1}-f_{i-1}}{2\Delta }}.$
  
  Where $\Delta$ is the spacing between points with index $i-1,\ i\ \&\ i+1$. The equation yields a fourth-order accurate solution for $f'$ when supplemented with suitable boundary conditions (typically periodic). When compared to the 4th-order accurate central explicit method;
  
  $f'_{i}={\frac {-f_{i+2}+8f_{i+1}-8f_{i-1}+f_{i-2}}{12\Delta }},$
  
  the former (implicit) method is compact as it only uses values on a 3-point stencil instead of 5.
  
  ## Derivation of compact schemes
  
  Compact schemes are derived using a Taylor series expansion. Say we wish to construct a compact scheme with a three-point stencil (as in the example):
  
  $\alpha _{1}f'_{i-1}+f'_{i}+\alpha _{2}f'_{i+1}=b_{1}f_{i+1}+af_{i}+b_{2}f_{i-1}.$
  
  From a symmetry argument we deduce $\alpha _{1}=\alpha _{2}=\alpha$, $a=0$ and $b_{1}=-b_{2}=-b$, resulting in a two-parameter system,
  
  $\alpha f'_{i-1}+f'_{i}+\alpha f'_{i+1}+bf_{i+1}-bf_{i-1}=0.$
  
  We write the expansions around $x_{i}$ up to a reasonable number of terms and using notation ${\frac {\mathrm {d} ^{n}f}{\mathrm {d} x^{n}}}=f^{n}$,
  
  ${\begin{aligned}f_{i+1}&=&f_{i}+\Delta &f'_{i}+{\frac {1}{2}}\Delta ^{2}&f_{i}^{2}+{\frac {1}{6}}\Delta ^{3}&f_{i}^{3}+{\frac {1}{24}}\Delta ^{4}f_{i}^{4}+\mathrm {etc.} ,\\f_{i-1}&=&f_{i}-\Delta &f'_{i}+{\frac {1}{2}}\Delta ^{2}&f_{i}^{2}-{\frac {1}{6}}\Delta ^{3}&f_{i}^{3}+{\frac {1}{24}}\Delta ^{4}f_{i}^{4}+\mathrm {etc.} ,\\f'_{i}&=&&f'_{i},\\f'_{i+1}&=&&f'_{i}+\Delta &f_{i}^{2}+{\frac {1}{2}}\Delta ^{2}&f_{i}^{3}+{\frac {1}{6}}\Delta ^{3}f_{i}^{4}+{\frac {1}{24}}\Delta ^{4}f_{i}^{5}+\mathrm {etc.} ,\\f'_{i-1}&=&&f'_{i}-\Delta &f_{i}^{2}+{\frac {1}{2}}\Delta ^{2}&f_{i}^{3}-{\frac {1}{6}}\Delta ^{3}f_{i}^{4}+{\frac {1}{24}}\Delta ^{4}f_{i}^{5}+\mathrm {etc.} ,\\\end{aligned}}$
  
  Each column on the right-hand side gives an equation for the coefficients $\alpha ,b$,
  
  ${\begin{aligned}f_{i}:&\ \ \ b-b&=0,&\ \mathrm {(Trivial)} \\f'_{i}:&\ \ \ 2\Delta b+1+2\alpha &=0,&\ \mathrm {(eq.\ 1)} \\f_{i}^{2}:&\ \ \ b-b+\alpha -\alpha &=0,&\ \mathrm {(Trivial)} \\f_{i}^{3}:&\ \ \ {\frac {1}{3}}b\Delta ^{3}+\Delta ^{2}\alpha &=0.&\ \mathrm {(eq.\ 2)} .\end{aligned}}$
  
  We now have two equations for two unknowns and therefore stop checking for higher-order-term equations.
  
  ${\begin{aligned}\mathrm {eq.\ 2} :&\ b={\frac {-3}{\Delta }}\alpha ,\rightarrow \\\mathrm {eq.\ 1} :&\ -6\alpha +1+2\alpha =0,\rightarrow \\&\alpha ={\frac {1}{4}},\ \mathrm {and} ,\ \rightarrow \\&b=-{\frac {3}{4\Delta }},\end{aligned}}$
  
  which is indeed the scheme from the example.
  
  ## List of compact schemes
  
  ### First derivative $f'_{i}$
  
  4th order central scheme:
  
  ${\frac {1}{4}}f'_{i-1}+f'_{i}+{\frac {1}{4}}f'_{i+1}={\frac {3}{2}}{\frac {f_{i+1}-f_{i-1}}{2\Delta }}.$
  
  6th order central scheme:
  
  ${\frac {1}{3}}f'_{i-1}+f'_{i}+{\frac {1}{3}}f'_{i+1}={\frac {14}{9}}{\frac {f_{i+1}-f_{i-1}}{2\Delta }}+{\frac {1}{9}}{\frac {f_{i+2}-f_{i-2}}{4\Delta }}.$
  
  