# Introduction: Finite Differences

The most common method for approximating differential equations is called finite difference (FD) or finite volume (FV). In this context the domain $\Omega \in \mathbb{R}^d$ is divided in uniform (i.e., they look exactly the same, just lying in different positions) subdomains $\{\Omega_i\}_i$ for $i=1,\dots,N$.

:::{note}
The subdomains can also be defined to be non-uniform, i.e. they can vary in size and shape. But to keep the discussion simple, we will ignore that case.
:::

Then, instead of finding a function $f$ solution of our differential equation, we find the set of values $\{f_i\}_i$ for $i=1,\dots,N$ seen as the value of the solution each subdomain.

In particular, we see it as the mean value in such domain, i.e.,

$$
  f_i = \frac{1}{|\Omega_i|} \int_{\Omega_i} f(x) \mathrm{d}x,
$$

and if the discretization is _fine_ enough (i.e., if the
subdomains are small enough), we expect the following approximation:

$$
  f_i \approx f(x) \quad \text{for } x \in \Omega_i.
$$

:::{prf:remark}
In this context $f$ is the mathematical solution, while $\{f_i\}_i$ are the approximations in each subdomain.
:::

The name of this discretization method refers to the approximation of the derivatives.
For example, the first-order derivative can be approximated using a **forward difference**

$$
  f'(x) \approx \frac{f(x+h) - f(x)}{h}.
$$

For set discretization steps $h_x, h_y, h_z > 0$ we define the regular grid

$$
  x_i = i h_x, \qquad y_j = j h_y, \qquad z_k = k h_z
$$

for $i=0,\dots,N_x$, $j=0,\dots,N_y$, and $k=0,\dots,N_z$.
Then each subdomain is defined as

$$
  \Omega_{i,j,k} = \{ (x,y,z) \in \mathbb{R}^3 | x_{i-1} \le x \le x_i, y_{j-1} \le y \le y_j, z_{k-1} \le z \le z_k\}.
$$

In this setting, derivatives are easily approximated:

$$
  \partial_x f(x) = f_x(x) \approx \frac{1}{h_x} \left( f_{i+1,j,k} - f_{i,j,k} \right) \qquad \text{if } x \in \Omega_{i,j,k}.
$$

This setting is very useful to evaluate derivates from local information, and is in general faster than other methods.
The biggest drawback, however, is the need to rely on regular, structured grid. This results in numerical errors in basically any geometry that is not a parallelepipeda.
