tested 1/6/2022.

Chapter 1

This is a GNU Octave version of the Fundamentals of Numerical Computation Jupyter Notebooks found at <https://tobydriscoll.net/project/fnc/ https://tobydriscoll.net/project/fnc/>_.

Example 1.1.2

Note that not all the digits displayed for |p| are the same as for 𝜋. As an approximation, its absolute and relative accuracy are

Example 1.1.3

There is no double precision number between 1 and $1+\epsilon_\mbox{mach}$. Thus the following difference is zero despite its appearance.

However, $1+\frac{\epsilon_\mbox{mach}}2$ is a double precision number, so it and its negative are represented exactly:

This is now the "correct" result. But we have found a rather shocking breakdown of the associative law of addition!

Example 1.3.2

Here we show how to use |horner| to evaluate a polynomial. We first define a vector of the coefficients of $p(x)=(x-1)^3=x^3-3x^2+3x-1,$ in descending degree order. [Need hornereval.m in the current directory, rewritten so as not to rewrite MATLAB's version. For Octave, the function can be defined in the script as shown below.]

% The above is the value of 𝑝(1.6)p(1.6), up to a rounding error. % Example 1.3.3 % Our first step is to construct a polynomial with six known roots.

Now we use a standard numerical method for finding those roots, pretending that we don't know them already. We also sort them from lowest to highest values.

Here are the relative errors in each of the computed roots. [Since r_computed is a column vector, we use its transpose.]

It seems that the forward error is acceptably close to machine epsilon for double precision in all cases except the double root at $x=1$. This is not a surprise, though, given the poor conditioning at such roots.

Let's consider the backward error. The data in the rootfinding problem are the polynomial coefficients. We can apply poly to find the coefficients of the polynomial (that is, the data) whose roots were actually computed by the numerical algorithm.

We find that in a relative sense, these coefficients are very close to those of the original, exact polynomial:

In summary, even though there are some computed roots relatively far from their correct values, they are nevertheless the roots of a polynomial that is very close to the original.

Example 1.3.4

So far, so good. But:

The first value is correct to all stored digits, but the second has fewer than six accurate digits:

Example 1.3.5

First, we find the "good" root using the quadratic forumla.

Then we use the alternative formula for computing the other root.