27 Polynomials
A big part of the high-school algebra curriculum is about polynomials. In some ways, this is appropriate since polynomials played an outsized part in the historical development of mathematical theory. Indeed, the so-called “Fundamental theorem of algebra” is about polynomials.1
For modelers, polynomials are a mixed bag. They are very widely used in modeling. Sometimes this is entirely appropriate, for instance the low-order polynomials that are the subject of Chapter Chapter 26. The problems come when high-order polynomials are selected for modeling purposes. Building a reliable model with high-order polynomials requires a deep knowledge of mathematics, and introduces serious potential pitfalls. Modern professional modelers learn the alternatives to high-order polynomials, but newcomers often draw on their experience in high-school and give unwarranted credence to polynomials. This chapter attempts to guide you to the ways you are likely to see polynomials in your future work and to help you avoid them when better alternatives are available.
27.1 Basics of polynomials with one input
A polynomial is a linear combination of a particular class of functions: power-law functions with non-negative, integer exponents: 1, 2, 3, …. The individual functions are called monomials, a word that echoes the construction of chemical polymers out of monomers; for instance, the material polyester is constructed by chaining together a basic chemical unit called an ester.
In one input, say
The domain of polynomials, like the power-law functions they are assembled from, is the real numbers, that is, the entire number line
Figure 27.1 shows a 7th order polynomial—that is, the highest-order term is
In contrast, for even-order polynomials (2, 4, 6, …) the function value in the two tail domains go in the same direction, either both to
In the wriggly domain in Figure 27.1, there are six argmins or argmaxes.
An
Note that the local polynomial approximations in Chapter Chapter 26 are at most 2nd order and so there is at most 1 wriggle: a unique argmax. If the approximation does not include the quadratic terms (
27.2 Multiple inputs?
High-order polynomials are rarely used with multiple inputs. One reason is the proliferation of coefficients. For instance, here is the third-order polynomial in two inputs,
This has 10 coefficients. With so many coefficients it is hard to ascribe meaning to any of them individually. And, insofar as some feature of the function does carry meaning in terms of the modeling situation, that meaning is spread out and hard to quantify.
27.3 High-order approximations
The potential attraction of high-order polynomials is that, with their wriggly interior, they can take on a large number of appearances. This chameleon-like behavior has historically made them the tool of choice for understanding the behavior of approximations. That theory has motivated the use of polynomials for modeling patterns in data, but, paradoxically, has shown that high-order polynomials should not be the tool of choice for modeling data.2
Polynomial functions lend themselves well to calculations, since the output from a polynomial function can be calculated using just the basic arithmetic functions: addition, subtraction, multiplication, and division. To illustrate, consider this polynomial:
Our example polynomial,
It is clear from the graph that the approximation is excellent near
One way to measure the quality of the approximation is the error
Figure 27.3 shows that for
That the graph of
The inevitable consequence of
Throughout this book, we’ve been using straight-line approximations to functions around an input
One way to look at
Start with a general, second-order polynomial centered around
The first- and second-derivatives, evaluated at
Notice the 2 in the above expression. When we want to write the coefficient
To make
This logic can also be applied to higher-order polynomials. For instance, to match the third derivative of
Remarkably, each coefficient in the approximating polynomial involves only the corresponding order of derivative.
Now we can explain where the polynomial that started this section,
Order | ||
---|---|---|
0 | ||
1 | ||
2 | ||
3 | ||
4 |
The first four derivatives of
The polynomial constructed by matching successive derivatives of a function
Let’s construct a 3rd-order Taylor polynomial approximation to
We know it will be a 3rd order polynomial:
The exponential function is particularly nice for examples because the function value and all its derivatives are identical:
The function value and derivatives of
Matching these to the exponential evaluated at
Result: the 3rd-order Taylor polynomial approximation to the exponential at
Figure 27.4 shows the exponential function
The polynomial is exact at
The plot of
27.4 Indeterminate forms
Let’s return to an issue that has bedeviled calculus students since Newton’s time. The example we will use is the function
The sinc() function (pronounced “sink”) is still important today, in part because of its role in converting discrete-time measurements (as in an mp3 recording of sound) into continuous signals.
What is the value of
On the other hand,
Still another answer is suggested by plotting out sinc(
The graph of sinc() looks smooth and the shape makes sense. Even if we zoom in very close to
Compare the well-behaved sinc() to a very closely related function (which does not seem to be so important in applied work):
Both
slice_plot(sin(x) / x ~ x, bounds(x=c(-0.1, 0.1)), npts=500) %>%
gf_refine(scale_y_log10())
slice_plot(sin(x) / x^3 ~ x, bounds(x=c(-0.1, 0.1)), npts=500) %>%
gf_refine(scale_y_log10())
Since both
Since we are interested in behavior near
near is already a polynomial. is already a polynomial.
Remember, these approximations are exact as
Even at
Compare this to the polynomial approximation to
Evaluating this at
The procedure for checking whether a function involving division by zero behaves well or poorly is described in the first-ever calculus textbook, published in 1697. The title (in English) is: The analysis into the infinitely small for the understanding of curved lines. In honor of the author, the Marquis de l’Hospital, the procedure is called l’Hopital’s rule.4
Conventionally, the relationship is written
Let’s try this out with our two example functions around
27.5 Computing with indeterminate forms
In the early days of electronic computers, division by zero would cause a fault in the computer, often signaled by stopping the calculation and printing an error message to some display. This was inconvenient, since programmers did not always forsee division-by-zero situations and avoid them.
As you’ve seen, modern computers have adopted a convention that simplifies programming considerably. Instead of stopping the calculation, the computer just carries on normally, but produces as a result one of two indeterminant forms: Inf
and NaN
.
Inf
is the output for the simple case of dividing zero into a non-zero number, for instance:
17/0
## [1] Inf
NaN
, standing for “not a number,” is the output for more challenging cases: dividing zero into zero, or multiplying Inf
by zero, or dividing Inf
by Inf
.
0/0
## [1] NaN
0 * Inf
## [1] NaN
Inf / Inf
## [1] NaN
The brilliance of the idea is that any calculation that involves NaN
will return a value of NaN
. This might seem to get us nowhere. But most programs are built out of other programs, usually written by other people interested in other applications. You can use those programs (mostly) without worrying about the implications of a divide by zero. If it is important to respond in some particularly way, you can always check the result for being NaN
in your own programs. (Much the same is true for Inf
, although dividing a non-Inf
number by Inf
will return 0.)
Plotting software will often treat NaN
values as “don’t plot this.” that is why it is possible to make a sensible plot of
27.6 Drill
Part 1 Here is a function
In the Taylor polynomial approximation to
- positive
- zero
- negative
- no such coefficient exists in a Taylor polynomial
Part 2 Here is a function
In the Taylor polynomial approximation to
- positive
- zero
- negative
- no such coefficient exists in a Taylor polynomial
Part 3 Here is a function
In the Taylor polynomial approximation to
- positive
- zero
- negative
- no such coefficient exists in a Taylor polynomial
Part 4 Here is a function
In the Taylor polynomial approximation to
- positive
- zero
- negative
- no such coefficient exists in a Taylor polynomial
Part 5 Here is a function
In the Taylor polynomial approximation to
- positive
- zero
- negative
- no such coefficient exists in a Taylor polynomial
Part 6 Here is a function
In the Taylor polynomial approximation to
- positive
- zero
- negative
- no such coefficient exists in a Taylor polynomial
Part 7 Here is a function
In the Taylor polynomial approximation to
- positive
- zero
- negative
- no such term exists in a Taylor polynomial
Part 8 Here is a function
In the Taylor polynomial approximation to
- positive
- zero
- negative
- no such term exists in a Taylor polynomial
Part 9 Here is a function
Two Taylor polynomials, centered on the same
- The third-order polynomial is brown.
- The third-order polynomial is magenta.
Part 10 Here is a function
with a Taylor polynomial shown in magenta. What is the order of the polynomial?
zero one two three four
27.7 Exercises
Exercise 27.01
The Taylor polynomial for
Part A In the above formula, the center
- Having a center is not a requirement for a Taylor polynomial.
- There is a center,
, but terms like were simplified to . - There is a center,
, but the terms like were simplified to .
Exercise 27.02
Here is a Taylor polynomial:
Part A Where is the center
Part B Your roommate suggests that
- No, a polynomial does not have functions like
. - Yes. The center is
. - Not really. The formula suggests that the center is
but the coefficients are wrong.
Exercise 27.03
Consider the function
Part A Using ordinary algebra,
- Yes, with a center at
- Yes, with a center at
- No, because there are no factorials involved
Exercise 27.04
Here’s the Taylor polynomial expansion of
Part A Which of these is the numerical value of
Problem with Differentiation Exercises/camel-sing-futon
Exercise 27.06
Consider the function
<- makeFun(sin(x-pi/6)~x)
f <- makeFun(-.5+x*sqrt(3)/2+.25*x^2-x^3/(4*sqrt(3))~x) T
In this exercise, we want to figure out the extent of the interval in which
slice_plot(f(x)+.05~x,bounds(x=-1:1))%>%
slice_plot(f(x)-.05~x)%>%
slice_plot(T(x)~x,color="red")
Part A Find the full interval of the domain of
Exercise 27.07
With very high-order derivatives, it can be awkward to use a notation with repeated subscripts, like
For a function
A Taylor polynomial, like all polynomials, is a linear combination of basic functions.
Part A Which of these are the basic functions being linearly combined in a Taylor polynomial?
Exercise 27.08
It is worth remembering the first couple of terms in the Taylor polynomial approximation of the sine and cosine functions.
Part A What is the order of the approximation to
First Second Third Fourth
Part B What is the order of the approximation to
First Second Third Fourth
Here are several different quantities to calculate involving limits. You will carry out the calculation by substituting the Taylor Polynomials given above, cancelling out
Example:
The
Exercise 27.09
Each of the three functions graphed below is a simple power-law function that can be written
Part A For the
0 1 2 3 4 5
Part B For the
0 1 2 3 4 5
Part C For the
0 1 2 3 4 5
Part D For the
0 1 2 3 4 5
Part E For the
-2 -1 0 1 2 3
Part F For the
0 1 2 3 4 5
Exercise 27.10
At
Using a sandbox, plot out
Part A From the graph, determine
-0.2 0 0.1 0.5 not well behaved
Use l’Hopital’s rule to confirm that
$$_{x} x (x) = [_{x} _x x]
[_{x} _x (x)]$$
Part B Does the application of l’Hopital’s rule confirm the result from graphing the function?
Yes No
Exercise 27.11
We would like to write a Taylor-series polynomial for
Here are the functions for the derivatives
Order | formula for derivative |
---|---|
0th | |
1st | |
2nd | |
3rd | |
4th | |
5th | |
6th | |
7th | |
8th |
- Write a Taylor polynomial function for
around ). To do this, you will have to evaluate each of the 9 formulas above at , producing a number. For example, the first five formulas will give 0.3989, 0, -0.3989, 0, 1.1968. This would expand into the following Taylor function:
= makeFun(0.3989 +
T_at_0 0*(x-x0) +
- 0.3989*(x-x0)^2/factorial(2) +
0*(x-x0)^3/factorial(3) +
1.1968*(x-x0)^4/factorial(4) ~ x,
x0=0)
You will need to add in the 6th, 7th, and 8th terms.
Plot
T_at_0(x) ~ x
over the domain , and pipe the result to a slice-plot ofdnorm(x) ~ x
so that you can compare the two plots.Define another function
T_at_1()
which will be much likeT_at_zero()
but withx0=1
and the coefficients changed to be the formulas evaluated at .Add a layer showing
T_at_1()
to your previous plot.
Say over what domain T_at_0()
is a good approximation to dnorm()
and over what domain T_at_1()
is a good approximation to dnorm()
. Do the two domains overlap?
- Write a piecewise function of this form:
<- makeFun(ifelse(abs(x) < 0.5,
T T_at_0(abs(x)),
T_at_1(abs(x))) ~ x)
Plot this out on top of dnorm()
to show whether T()
is a good approximation to dnorm()
.
You could continue on to define T_at_2()
and incorporate that into the piecewise T()
, and so on, to construct an approximation to dnorm()
that is accurate over a larger domain.
The fundamental theorem says that an order-n polynomial has n roots (including multiplicities).↩︎
The mathematical background needed for those better tools won’t be available to us until Block 5, when we explore linear algebra.↩︎
Unfortunately for these human calculators, pencils weren’t invented until 1795. Prior to the introduction of this advanced, graphite-based computing technology, mathematicians had to use quill and ink.↩︎
In many French words, the sequence “os” has been replaced by a single, accented letter,
.↩︎