Computazionale-OLD/1. Error Analysis/1.2. Errori aritmetici in virgola mobile e errori di arrotondamento/Readme.md
2025-04-04 23:58:04 +02:00

71 lines
No EOL
2.4 KiB
Markdown

# Error Analysis
In computational applications there are two main sources of error that we need to worry about:
1. roundoff (or rounding) errors
2. approximation errors
**Rounding errors** originate from the necessity of having to represent numbers in a computer using a finite number of digits. **Approximation errors**, instead, refer to those errors that are intrinsic of the way we numerically solve a specific problem. In particular, these would be present even in the ideal case where we were able to carry out the computation without rounding errors.
A simple example of approximation error can be seen in the case where we estimate the value of the function
$$
e^x = \sum_{n=0}^{\infty} {x^n\over n!} = 1 + x + {x^2\over 2} + {x^3\over 3!} + \ldots
\
\approx
\
\sum_{n=0}^{n_{\rm max}} {x^n\over n!}\,,
$$
by evaluating the series only up to a finite order $n_{\rm max}<\infty$. In this case, the approximation comes with a *truncation error* of ${\rm O}(x^{n_{\rm max}+1})$.
:::i "Info"
aasdasdasd
:::
> [!NOTE]
> Let $f(x)$ and $g(x)$ be two functions defined on some unbounded subset $D$ of the positive real numbers, and $g(x)$ be non-zero in a neighborhood of $a\in D$ (often $a=0$). We write
$$
f(x)={\rm O}(g(x))
\quad
\text{as}
\quad
x\to a
$$
> if there exist positive numbers $\delta$ and $M$ such that for all $x$ with $0 < |x-a| < \delta$,
$$
|f(x)| \leq M |g(x)|\,.
$$
> Equivalently, we may say that $f(x)={\rm O}(g(x))$ if
$$
\underset{x\to a}{\lim \sup}{|f(x)|\over |g(x)|}<\infty\,.
$$
> If, instead, it holds that
$$
\underset{x\to a}{\lim}{f(x)\over g(x)}=1\,,
$$
>we write $f(x) \sim g(x)$ as $x\to a$.
In this chapter, we present a general discussion on *roundoff errors*, not tied to a specific numerical problem we want to solve. In later chapters, we discuss several different methods to solve specific problems and study their approximation errors in detail.
<font size= "6"> Exercises </font>
1. Consider the function $f(x)=e^x$ in the interval $x\in [0,1]$. Write a program that calculates the corresponding approximating series:
$$
g_N(x)=\sum_{n=0}^N {x^n\over n!}\,.
$$
**(a)** Verify that the absolute error $\Delta=|f(x)-g_N(x)|$ scales approximately with $x^{N+1}/(N+1)!$ for $N=1,2,3,4$.
**(b)** The error $\Delta$, in the given interval in $x$, differs from $x^{N+1}/(N+1)!$ . Why is that and for which values of $x$?