This version was implemented 12/21/2021. In [7] packages need to be imported if not already installed. Also, this calls chapter01.jl which contains the function horner. Also, the function poly in [18] and [21] should be fromroots. See https://juliamath.github.io/Polynomials.jl/stable/.

Example 1.1.2

Recall the grade-school approximation to the number $\pi$.

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

Example 1.1.3

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

However, $1-\varepsilon_\text{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. It's not a part of core Julia, so we need to load it first. All functions for this text are loaded using the following line.

Now we define a vector of the coefficients of $p(x)=(x-1)^3=x^3-3x^2+3x-1$, in descending degree order.

In order to avoid clashes between similarly named functions, Julia has sandboxed all the book functions into a namespace called FNC. We use this namespace whenever we invoke one of the functions.

The above is the value (up to roundoff) of $p(1.6)$. While it does lead to a little extra typing, a nice side effect of using the namespace paradigm is that if you type FNC. (including the period) and hit the TAB key, you will see a list of all the functions known in that namespace.

Example 1.3.3

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

Example 1.3.4

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

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

Example 1.3.5

For this example we will use a publicly available package for working with polynomials. It should be available using the following line, if you have followed installation instructions for these scripts.

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.

Here are the relative errors in each of the computed roots. The @. notation at the start means essentially to do the given operations on each element of the given vectors.

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.