Polynomials
Horner’s Scheme
Consider the polynomial \(\mathsf{P(x)} = \mathsf{3x^3 + 2x^2  4x + 7}\). Computing its value for a particular \(\mathsf{x}\) by means of the most naive ordering of arithmetic operations leads to the following code:
3*x*x*x + 2*x*x  4*x + 7
The number of operations (multiplications and additions) is
But if instead we factor the polynomial as a nested evaluation of monomials, i.e., \(\mathsf{P(x)} = \mathsf{((3x + 2)x  4)x + 7}\), then we find that
((3*x + 2)*x  4)*x + 7
requires only 6 operations. This is a very small savings, but it might be meaningful if computing \(\mathsf{P(x)}\) had to be performed many times (in an inner loop of the program, say). The efficiency gain is correspondingly more significant if the degree of the polynomial is higher. For a polynomial of degree \(\mathsf{n}\) the naive calculation requires
operations. On the other hand, organized in the form \(\mathsf{P(x)} = \mathsf{(((a_nx_n + a_{n1})x + a_{n2})x + )x + a_0},\) the calculation requires only \(\mathsf{2n}\) operations—one addition and one multiplication at each of the \(\mathsf{n}\) levels of nesting.
In socalled “bigO” notation, we say that the naive scheme scales as \(\mathsf{O(n^2)}\), whereas Horner’s scheme scales as \(\mathsf{O(n)}\).
Polynomial division
Suppose the polynomial \(\mathsf{P(x)}\) can be written as \(\mathsf{P(x)} = \mathsf{Q(x)p(x) + r(x)}\) where \(\mathsf{r(x)}\) has degree less than that of \(\mathsf{p(x)}\). If we specialize to the monomial case, \(\mathsf{p(x)} = \mathsf{xc}\), then it must be that \(\mathsf{r(x)} = \mathsf{r}\) has degree zero (constant function). Hence,
and
The roots of \(\mathsf{P(x)}\) constitute the set of values \(\mathsf{\{c\}}\) for which polynomial division \(\mathsf{P(x)/(xc)}\) yields remainder \(\mathsf{r} = \mathsf{0}\). (This is just another way of saying that the roots of \(\mathsf{P(x)}\) can be read off from its monomial factorization.) The process of dividing out a root factor is called deflation. We say that \(\mathsf{Q(x)}\) is deflated with respect to \(\mathsf{P(x)}\).
Synthetic division
Horner’s scheme is sometimes referred to as synthetic division. To see why this is, think about the intermediate values that are calculated along the way. For example, to evaluate the order\(\mathsf{N}\) polynomial \(\mathsf{P(x)} = \mathsf{(\cdots((a_Nx^N+ a_{N1})x + a_{N2})x + \cdots)x + a_0}\) at \(\mathsf{x = c}\), we must compute from the inside out the following \(\mathsf{N}\) terms:
This cycle of updates (\(\mathsf{q_N} = \mathsf{0, q_{k1} = cq_k+ a_k}\)) terminates with the result \(\mathsf{P(c)} = \mathsf{cq_0 + a_0}\).
Moreover, we can show that the coefficients \(\mathsf{q_0}, \mathsf{q_1}, \ldots, \mathsf{q_{N1}}\) are precisely those of the quotient polynomial \(\mathsf{Q(x)}\) that results when \(\mathsf{P(x)}\) is divided by \(\mathsf{(xc)}\):
The proof is quite simple.
Consider the following bookkeeping trick (much like long division!) for generation of the \(\mathsf{q_k}\) coefficients. Suppose we want to evaluate \(\mathsf{P(x)} = \mathsf{3x^3+2x^24x+7}\) at \(\mathsf{x = 1}\). We start by setting up a table containing the value of \(\mathsf{x}\) and the coefficients of \(\mathsf{P}\) in a row at the top:
1  3 2 4 7


Allow the first entry to drop.
1  3 2 4 7

 3
Create a new entry in the second column by multiplying the lowest entry in the first column by the value to the left of the vertical bar.
1  3 2 4 7
 3
 3
Sum the second column and repeat.
1  3 2 4 7
 3
 3 1
1  3 2 4 7
 3 1
 3 1 3
1  3 2 4 7
 3 1 3
 3 1 3 10
We read off the remainder from the final entry on the bottom right. That is, \(\mathsf{P(1) = 10}\). Similarly, we can show that \(\mathsf{P(0) = 7}\), \(\mathsf{P(1) = 8}\), and \(\mathsf{P(2) = 31}\).
0  3 2 4 7
 0 0 0
 3 2 4 7
1  3 2 4 7
 3 5 1
 3 5 1 8
2  3 2 4 7
 6 16 24
 3 8 12 31
The other terms in the bottom row are the corresponding \(q_k\) values.
Consider the following polynomial with roots 1, 2, and 3:
The polynomial division theorem tells us that \(\mathsf{P(x)}\) has a factor \(\mathsf{(xc)}\) if and only if \(\mathsf{P(c)} = \mathsf{0}\).
Let’s show explicitly that \(\mathsf{P(x)/(x2)} = \mathsf{2x^28x+6}\). The remainder is \(\mathsf{P(2)} = \mathsf{0}\).
2  2 12 22 12
 4 16 12
 2 8 6 0
Similarly, \(\mathsf{P(x)/(x3)} = \mathsf{2x^26x + 4}\).
3  2 12 22 12
 6 18 12
 2 6 4 0
Here’s an example with a nonzero remainder: \(\mathsf{P(x)/(x4)} = \mathsf{2x^2  4x + 6 + 12/(x4)}\)
4  2 12 22 12
 8 16 24
 2 4 6 12
And another example with a nonzero remainder: \(\mathsf{P(x)/x} = \mathsf{2x^2 12x + 22 12/x}\).
0  2 12 22 12
 0 0 0
 2 12 22 12
Cauchy’s bound
If we want to find the real roots of a polynomial \(\mathsf{P(x)} = \mathsf{a_0} + \mathsf{a_1x} + \cdots + \mathsf{a_Nx^N}\), we know that there are at most \(\mathsf{N}\) of them. But if we want to use Newton’s method, we would like to have some hint as to where to start looking for them. A theorem due to Cauchy tells us that every root \(\mathsf{c}\) satisfies \(\mathsf{c} \le \mathsf{1} + \max \mathsf{a_k/a_N}\), where the maximum is over all \(\mathsf{k} = \mathsf{0}, \mathsf{1}, \mathsf{2}, \ldots, \mathsf{N}\). That is, there is a bound on the distance from the origin.
For example, the roots of
all live in the interval \([\mathsf{M},\mathsf{M}]\) with \(\mathsf{M} = \mathsf{1 + 22/2} = \mathsf{12}\).
Note that this is a relatively weak bound and not always useful for very high degree polynomials.
Multiplicities
It is possible to have roots that coincide, e.g., \(\mathsf{P(x)} = \mathsf{(x1)(x2)} \cdots \mathsf{(xu)} \cdots \mathsf{(xv)}\) with \(\mathsf{u = v}\). (It may either be that \(\mathsf{u = v}\) exactly or that they agree within floating point accuracy!) We say that \(\mathsf{P(x)}\) has a root \(c\) of multiplicity \(\mathsf{m}\) if \(\mathsf{(xc)^m}\) divides \(\mathsf{P}\) but \(\mathsf{(xc)^{m+1}}\) does not. Higher multiplicities reduce the rate of convergence of Newton’s algorithm but are not fatal.
Root finding algorithm
Putting all these idea together, we arrive at a good rootfinding algorithm for polynomials:
Use Cauchy’s bound to find an interval \([\mathsf{M},\mathsf{M}]\) that contains the roots
Perform Newton’s method iterations starting from some \(\mathsf{x}_{\textsf{guess}} \in [\mathsf{M},\mathsf{M}]\)
If Newton’s method converges to a point \(\mathsf{c}\), try to deflate \(\mathsf{P(x)}\) by \(\mathsf{(xc)}\), \(\mathsf{(xc)^2}\), \(\mathsf{(xc)^3}\), etc.
Repeat until there are no more roots.
Polynomial Interpolation
Suppose that we are given a set of \(N+1\) coordinate pairs \(\{ (\mathsf{x_n,y_n}) \}\), which we interpret as being derived from a functional relationship \(\mathsf{y_n} = \mathsf{f(x_n)}\). Is there any way to deduce \(\mathsf{f}:\mathbb{R}\to\mathbb{R}\) from the data points? In fact, there is not, even if we impose additional conditions, such as smoothness or differentiability.
It is possible to find a polynomial approximation \(\mathsf{p(x)}\) such that \(\mathsf{y_n} = \mathsf{p(x_n)} = \mathsf{f(x_n)}\). An \(\mathsf{N}\)thorder polynomial
has \(\mathsf{N+1}\) coefficients (free parameters) that can be fixed uniquely by the requirement that it pass through the \(\mathsf{N+1}\) known coordinates.
This system of equations is linear in the coefficients of \(\mathsf{p(x)}\). Hence, it can be recast as a matrix equation
of the form \(\mathsf{X\mathbf{p} = \mathbf{y}}\). Provided that the matrix \(\mathsf{X}\) is nonsingular, there is a unique solution \(\mathsf{\mathbf{p} = X^{1} \mathbf{y}}\).
For example, suppose that we know the function at two points \(\mathsf{(x_0,y_0)}\) and \(\mathsf{(x_1,y_1)}\). A linear interpolation between the two points must satisfy
Hence,
which yields a linear polynomial
Try this on your own
Convince yourself that \(\mathsf{p(x_0) = y_0}\) and \(\mathsf{p(x_1) = y_1}\).
Lagrange Polynomials
The polynomial in the previous example can be rewritten as follows:
The functions \(\mathsf{l_0(x)}\) and \(\mathsf{l_1(x)}\) are called Lagrange polynomials. There are defined relative to a particular set \(\{\mathsf{x_n}\}\) and can be generalized to arbitrary order:
Note that these are constructed such that each \(\mathsf{l_n(x)}\) is a polynomial of degree \(\mathsf{N}\) and has the property that \(\mathsf{l_n(x_m) = \delta_{n,m}}\). The polynomial has an expansion
See also
The same polynomial fitting construction can be carried out recursively using Neville’s algorithm:
Runge’s Phenomenon
We explored this is in class in some depth. Runge’s phenomenon refers to the tendency of a highorder interpolating polynomial to becoming increasingly oscillatory at high order.
There is a unique order\(\mathsf{N}\) polynomial \(\mathsf{P(x)}\) passing through the \(\mathsf{N+1}\) coordinate pairs \(\mathsf{(x_i,y_i)}\). If those points represent a sampling of some function \(\mathsf{f}\), with \(\mathsf{y_i = f(x_i)}\) on a mesh \(\mathsf{x_i}\), then \(\mathsf{P}\) can be understood as an approximation to \(\mathsf{f}\). As \(\mathsf{N}\) gets large, and especially if the \(\mathsf{x_i}\) mesh is uniform, the polynomial approximation actually gets worse.
Splines
An important lesson from Runge’s phenomenon is that very high order polynomials are generally not reliable. An alternative—especially useful for interpolation—is to take the fitting function to be a loworder polynomial defined piecewise. Suppose that we have a data set \(\{(\mathsf{x_n,y_n})\}\) and a collection of polynomial fitting functions. Here, we’ll suppose that \(\mathsf{s_{i1}(x)}\), \(\mathsf{s_i(x)}\), and \(\mathsf{s_{i+1}(x)}\) cover the intervals \([\mathsf{x_{i1},x_i}]\), \([\mathsf{x_i,x_{i+1}}]\), and \([\mathsf{x_{i+1},x_{i+2}}]\), respectively.
Linear Splines
If the fitting functions are linear, then the requirements of continuity and interpolation through \(\{(\mathsf{x_n,y_n})\}\) are enough to completely determine all the free parameters: \(\mathsf{s_{i1}(x_i)} = \mathsf{s_i(x_i)} = \mathsf{y_i}\), \(\mathsf{s_i(x_{i+1})} = \mathsf{s_{i+1}(x_{i+1})} = \mathsf{y_{i+1}}\), etc.
We can improve the quality of the interpolation by raising the order of the polynomials and imposing some degree of smoothness at each joint (or knot).
Quadratic Splines
In each slice of the domain, we assume a second order polynomial fitting function,
Fidelity with the data set requires \(\mathsf{s_n(x_n)} = \mathsf{y_n}\), which implies that \(\mathsf{a_n} = \mathsf{y_n}\). Ensuring that the slopes agree, \(\mathsf{s_{n1}'(x_n)} = \mathsf{s_n'(x_n)}\), leads to
Hence, \(\mathsf{2c_i} = \mathsf{(b_{i+1}b_i)/(x_{i+1}x_i)}\), and
The continuity requirement \(\mathsf{s_{n1}(x_n)} = \mathsf{s_n(x_n)}\) gives
which is to say that the next linear term is equal to minus the previous linear term plus twice the next straightline splope. But this recursion has to be seeded with a value for \(b_0\).
One possibility is to choose \(\mathsf{b_0} := \mathsf{(y_1y_0)/(x_1x_0)}\). Another is to minimize the total length of the curve:
Cubic Splines
The additional conditions of matching first and second derivatives \(\mathsf{s_{i1}'(x_i)} = \mathsf{s_i'(x_i)}\) and \(\mathsf{s_{i1}''(x_i)} = \mathsf{s_i''(x_i)}\) determine the coefficients of a cubic spline. The only complication is that two additional conditions are required at the endpoints. One can either fix the slopes at either end, if those values are known, or impose \(\mathsf{s_0''(x_0)} = \mathsf{s_{N1}(x_N)} = \mathsf{0}\).
Note that there are two few conditions imposed and hence two free parameters in the fit. We have to impose addition conditions, constraints, or assumptions. Here are two commonly used schemes:
 Clamped
The slopes at the two end points are fixed, \(\mathsf{s_0'(x_0)} = \mathsf{u}\) and \(\mathsf{s_{N1}'(x_N)} = \mathsf{v}\).
 Natural
The curvature at the two end points is made to vanish, \(\mathsf{s_0''(x_0)} = \mathsf{s_{N1}''(x_N)} = \mathsf{0}\).
Try this on your own
Determine \(\mathsf{a}\), \(\mathsf{b}\), and \(\mathsf{c}\) such that
is a natural cubic spline on the interval \([\mathsf{0,2}]\).