# Error measure for a simple finite difference scheme

I am responsible for assisting with certain error measurements for an FE program. The idea is to set up some benchmark comparisons which we can use for future development of the program.

To simplify the task I chose to look at a simple finite difference scheme for the equation of a parabola. Consider discrete values of $x_i$ where $\mathbb{x}$ is a vector:

$$\mathbb{x} = \left< \begin{matrix} 0&1&2&3&4&5&6&7\end{matrix}\right>$$

Now consider a mapping of $\mathbb{x}\rightarrow\mathbb{f}$ where $f_i = x_i^2$. It sounds fancy when I say it like that but its really just making a new vector with each value in it equalling the value $x_i^2$. $$\mathbb{f} = \left< \begin{matrix} 0&1&4&9&16&25&36&49\end{matrix}\right>$$

Plotting $\mathbb{f}$ versus $\mathbb{x}$ yields some sort of discretized parabola. The numerical derivative of this would be

$$\mathbb{df}_{num} = \left< \begin{matrix} 1&3&5&7&9&11&13&15\end{matrix}\right>$$

Using a very simple finite difference scheme of: $$df_i = \frac{f_{i+1}-f_i}{x_{i+1}-x_i}$$

It will also be noted that $\mathbb{df}_{num}$ contains one less term than $\mathbb{f}$. This, I believe, is inherent to finite differences.

The analytical counterpart for $\mathbb{df}$ which follows from $\frac {d }{d x}x^2 = 2x$ would be

$$\mathbb{df}_{a} = \left< \begin{matrix} 0&2&4&6&8&10&12&14\end{matrix}\right>$$.

Now subtracting the 2 vectors we get $\mathbb{f}_a-\mathbb{f}_{num} = \left< \begin{matrix} -1&-1&-1&-1&-1&-1&-1&-1\end{matrix}\right>$

Which is a sort of crude error measure.

What would be a better error measure? Something that would be simple to implement for things like this but precise enough that it can spot deviations efficiently in the context of a script? The idea is to have an error vector like this and compare each value in it with some sort of threshhold value, though we have no idea what this threshhold value would be...

• The error measure is good but the problem is that the finite difference method is used with $\Delta x=x_{i+1}-x_i$ way too large. Rembemer the derivative is theoretically the limit of this expression when $\Delta x\rightarrow 0$ where you have taken 1. The reason there is one less term in df is simply because for the last term you would need the $x_{n+1}$ to evaluate the derivative which you do not have. Oct 13, 2017 at 10:11

The error measure you have is not appropriate. That's because if you compute the quantities $df_i = \frac{f_{i+1}-f_i}{x_{i+1}-x_i}$, then they essentially approximate the error at location $\frac{x_{i+1}+x_i}{2}$, i.e., the midpoint between $x_{i+1}$ and $x_i$, and not at $x_i$ as you suggest. Consequently, your difference $f_a-f_{num}$ will only ever converge with ${\cal O}(\Delta x)$ even if your scheme is actually of higher order.
As for a better suggestion: Think of the solution of your PDE as a function, $u(x)$, and of the discrete approximation as a function $u_h(x)$. In the case of finite differences you could, for example, interpolate linearly between adjacent nodes. Then an appropriate measure would be $\int |u(x)-u_h(x)|^2 dx$ or the "energy error" $\int |u'(x)-u'_h(x)|^2 dx$.