"
]
},
{
"cell_type": "markdown",
"metadata": {
"lines_to_next_cell": 0
},
"source": [
"# Finite volumes 8 - finite-difference approximations"
]
},
{
"cell_type": "markdown",
"metadata": {
"lines_to_next_cell": 0
},
"source": [
"\n",
"\n",
"## Learning goals\n",
"1. Be able to develop finite-difference approximations for first and second derivatives (total and partial).\n",
"2. Be able to determine the truncation error and order of a finite - difference approximation from Taylor-series analysis.\n",
"3. Can construction forwards, backwards and central finite difference approximation stencils.\n",
"4. Can distinguish truncation error from roundoff error.\n",
"5. Can identify the controls truncation error, and recognize pathological situations which lead to large truncation errors.\n",
"6. Using a finite-difference stencil, can construct the system of equations for a finite-difference approximation to an ordinary or partial differential equation, including defining the grid of nodes and applying first-type (Dirichlet) and second-type (Neumann) boundary conditions.\n",
"7. Can compare and contrast and finite-difference approximation to a finite-volume approximation (this last learning will only become apparent after we introduce the integral formulation of the finite-volume method and of our conservation PDEs).\n",
"\n",
"Advanced reference: LeVeque, Randal J, *Finite difference methods for ordinary and partial differential equations: Steady-state and time-dependent problems,* 2007 (can be downloaded from UBC library here: __[UBC library link](http://gw2jh3xr2c.search.serialssolutions.com/?ctx_ver=Z39.88-2004&ctx_enc=info%3Aofi%2Fenc%3AUTF-8&rfr_id=info%3Asid%2Fsummon.serialssolutions.com&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.title=Finite+difference+methods+for+ordinary+and+partial+differential+equations&rft.au=LeVeque%2C+Randall+J&rft.date=2007-01-01&rft.pub=Society+for+Industrial+and+Applied+Mathematics&rft.isbn=9780898716290&rft.externalDocID=SIAMB0000334¶mdict=en-US)__ "
]
},
{
"cell_type": "markdown",
"metadata": {
"lines_to_next_cell": 0
},
"source": [
"## Finite-difference approximations to derivatives\n",
"\n",
"In notebook `6_finite_volume_4.ipynb` (https://phaustin.github.io/eosc213/web_notebooks/6_finite_volume_4.html) we were inspired to approximate the $x$ component of the gradient in concentration as\n",
"\n",
"
\n",
"where $\\Delta x$ is not infinitesimal, based upon the definition of the derivative where it is:\n",
"
\n",
"\n",
"\\begin{align}\n",
"{\\partial c \\over \\partial x} &= \\lim_{\\Delta x \\rightarrow 0} {c(x+\\Delta x) - c(x)\\over \\Delta x} \\label{fd882}\\\\\n",
"\\end{align}\n",
"\n",
"where $c(x+\\Delta x)$ is notation for \"the concentration at the point $x+\\Delta x, y, z$\".\n",
"\n",
"
\n",
"\n",
"Here we want to evaluate the accuracy of these finite-difference approximations. To do that, we need to look at **Taylor series representations** of functions.\n",
"
\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"lines_to_next_cell": 0
},
"source": [
"### Intuition\n",
"\n",
"Let's first look at a simple function that we know so we can calculate the derivatives using calculus and compare them to the our finite-difference approximations. Then we'll dig into the theory using Taylor Series.\n",
"
\n",
"Let's try the following function which is easy to plot and differentiate:\n",
"