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.

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 x, the monomials are x1,x2,x3, and so on. (There is also x0, but that is better thought of as the constant function.) An n-th order polynomial has monomials up to exponent n. For example, the form of a third-order polynomial is

a0+a1x1+a2x2+a3x3

The domain of polynomials, like the power-law functions they are assembled from, is the real numbers, that is, the entire number line <x<. But for the purposes of understanding the shape of high-order polynomials, it is helpful to divide the domain into three parts: a wriggly domain at the center and two tail domains to the right and left of the center.

Figure 27.1: A nth-order polynomial can have up to n1 critical points that it wriggles among. A 7-th order polynomial is shown here in which there are six local maxima or minima alternatingly.

Figure 27.1 shows a 7th order polynomial—that is, the highest-order term is x7. In one of the tail domains the function value heads off to , in the other to . This is a necessary feature of all odd-order polynomials: 1, 3, 5, 7, …

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 (Hands up!) or both to .

In the wriggly domain in Figure 27.1, there are six argmins or argmaxes.

An nth-order polynomial can have up to n1 extrema.

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 (x2 or y2) then there is no argmax for the function.

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, x, and y.

b0+bxx+byyfirst-order terms+bxyxy+bxxx2+byyy2second-order terms+bxxyx2y+bxyyxy2+bxxxx3+byyyy3third-order terms

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.

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: g(x)x16x3 Since the highest-order term is x3 this is a third-order polynomial. (As you will see, we picked these particular coefficients, 0, 1, 0, -1/6, for a reason.) With such simple coefficients the polynomial is easy to handle by mental arithmetic. For instance, for g(x=1) is 5/6. Similarly, g(x=1/2)=23/48 and g(x=2)=2/3. A person of today’s generation would use an electronic calculator for more complicated inputs, but the mathematicians of Newton’s time were accomplished human calculators. It would have been well within their capabilities to calculate, using paper and pencil, g(π/4)=0.7046527.

Our example polynomial, g(x)x16x3, graphed in color in Figure 27.2, does not look exactly like the sinusoid. If we increased the extent of the graphics domain, the disagreement would be even more striking, since the sinusoid’s output is always in 1sin(x)1, while the polynomial’s tails are heading off to and . But, for a small interval around x=0, exactly aligns with the sinusoid.

Figure 27.2: The polynomial g(x)xx3/6 is remarkably similar to sin(x) near x=0.

It is clear from the graph that the approximation is excellent near x=0 and gets worse as x gets larger. The approximation is poor for x±2. We know enough about polynomials to say that the approximation will not get better for larger x; the sine function has a range of 1 to 1, while the left and right tails of the polynomial are heading off to and respectively.

One way to measure the quality of the approximation is the error E(x) which gives, as a function of x, the difference between the actual sinusoid and the approximation: E(x)|sin(x)g(x)| The absolute value used in defining the error reflects our interest in how far the approximation is from the actual function and not so much in whether the approximation is below or above the actual function. Figure 27.3 shows E(x) as a function of x. Since the error is the same on both sides of x=0, only the positive x domain is shown.

Figure 27.3: The error E(x) of xx3/6 as an approximation to sin(x). Top panel: linear scale. Bottom panel: on a log-log scale.

Figure 27.3 shows that for x<0.3, the error in the polynomial approximation to sin(x) is in the 5th decimal place. For instance, sin(0.3)=0.2955202 while g(0.3)=0.2955000.

That the graph of E(x) is a straight-line on log-log scales diagnoses E(x) as a power law. That is: E(x)=Axp. As always for power-law functions, we can estimate the exponent p from the slope of the graph. It is easy to see that the slope is positive, so p must also be positive.

The inevitable consequence of E(x) being a power-law function with positive p is that limx0E(x)=0. That is, the polynomial approximation x16x3 is exact as x0.

Throughout this book, we’ve been using straight-line approximations to functions around an input x0.

g(x)=f(x0)+xf(x0)[xx0]

One way to look at g(x) is as a straight-line function. Another way is as a first-order polynomial. This raises the question of what a second-order polynomial approximation should be. Rather than the polynomial matching just the slope of f(x) at x0, we can arrange things so that the second-order polynomial will also match the curvature of the f(). Since the curvature involves only the first and second derivatives of a function, the polynomial constructed to match both the first and the second derivative will necessarily match the slope and curvature of f(). This can be accomplished by setting the polynomial coefficients appropriately.

Start with a general, second-order polynomial centered around x0:

g(x)a0+a1[xx0]+a2[xx0]2

The first- and second-derivatives, evaluated at x=x0 are:

xg(x)|x=x0=a1+2a2[xx0]|x=x0=a1

xxg(x)|x=x0=2a2

Notice the 2 in the above expression. When we want to write the coefficient a2 in terms of the second derivative of g(), we will end up with

a2=12xxg(x)|x=x0

To make g(x) approximate f(x) at x=x0, we need merely set

a1=xf(x)|x=x0 and

a2=12xxf(x)|x=x0

This logic can also be applied to higher-order polynomials. For instance, to match the third derivative of f(x) at x0, set

a3=16xxxf(x)|x=x0

Remarkably, each coefficient in the approximating polynomial involves only the corresponding order of derivative. a1 involves only xf(x)|x=x0; the a2 coefficient involves only xxf(x)|x=x0; the a3 coefficient involves only xxf(x)|x=x0, and so on.

Now we can explain where the polynomial that started this section, x16x3 came from and why those coefficients make the polynmomial approximate the sinusoid near x=0.

Order sin(x) derivative x16x3 derivative
0 sin(x)|x=0=0 (116x3)|x=0=0
1 cos(x)|x=0=1 (136x2)|x=0=1
2 sin(x)|x=0=0 (66x)|x=0=0
3 cos(x)|x=0=1 1|x=0=1
4 sin(x)|x=0=0 0|x=0=0

The first four derivatives of x16x3 exactly match, at x=0, the first four derivatives of sin(x).

The polynomial constructed by matching successive derivatives of a function f(x) at some input x0 is called a Taylor polynomial.

Let’s construct a 3rd-order Taylor polynomial approximation to f(x)=ex around x=0.

We know it will be a 3rd order polynomial:

gexp(x)a0+a1x+a2x2+a3x3

The exponential function is particularly nice for examples because the function value and all its derivatives are identical: ex. So

f(x=0)=1

xf(x=0)=1

xxf(x=0)=1

xxxf(x=0)=1 and so on.

The function value and derivatives of gexp(x) at x=0 are:

gexp(x=0)=a0

xgexp(x=0)=a1

xxgexp(x=0)=2a2

xxxgexp(x=0)=23a3=6a3

Matching these to the exponential evaluated at x=0, we get

a0=1

a1=1

a2=12

a3=123=16

Result: the 3rd-order Taylor polynomial approximation to the exponential at x=0 is gexp(x)=1+x+12x2+123x3+1234x4

Figure 27.4 shows the exponential function ex and its 3th-order Taylor polynomial approximation near x=0:

Figure 27.4: The 3th-order Taylor polynomial approximation to ex arount x=0

The polynomial is exact at x=0. The error E(x) grows with increasing distance from x=0:

Figure 27.5: The error from a 3rd-order Taylor polynomial approximation to ex around x=0 is a power-law function with exponent 4.

Figure 27.6: The error from a 3rd-order Taylor polynomial approximation to ex around x=0 is a power-law function with exponent 4.

The plot of log10E(x) versus log10|x| in ?fig-taylor-exp-5 shows that the error grows from zero at x=0 as a power-law function. Measuring the exponent of the power-law from the slope of the graph on log-log axes give E(x)=a|xx0|5. This is typical of Taylor polynomials: for a polynomial of degree n, the error will grow as a power-law with exponent n+1. This means that the higher is n, the faster limxx0E(x)0. On the other hand, since Ex is a power law function, as x gets further from x0 the error grows as (xx0)n+1.

Math in the World: Polynomial models of other functions

Brooke Taylor (1685-1731), a near contemporary of Newton, published his work on approximating polynomials in 1715. Wikipedia reports: “[T]he importance of [this] remained unrecognized until 1772, when Joseph-Louis Lagrange realized its usefulness and termed it ‘the main [theoretical] foundation of differential calculus’.”Source

Figure 27.7: Brook Taylor

Due to the importance of Taylor polynomials in the development of calculus, and their prominence in many calculus textbooks, many students assume their use extends to constructing models from data. They also assume that third- and higher-order monomials are a good basis for modeling data. Both these assumptions are wrong. Least squares is the proper foundation for working with data.

Taylor’s work preceded by about a century the development of techniques for working with data. One of the pioneers in these new techniques was Carl Friedrich Gauss (1777-1855), after whom the gaussian function is named. Gauss’s techniques are the foundation of an incredibly important statistical method that is ubiquitous today: least squares. Least squares provides an entirely different way to find the coefficients on approximating polynomials (and an infinite variety of other function forms). The R/mosaic fitModel() function for polishing parameter estimates is based on least squares. In Block 5, we will explore least squares and the mathematics underlying the calculations of least-squares estimates of parameters.

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 sinc(x)sin(x)x

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 sinc(0)? One answer, favored by arithmetic teachers is that sinc(0) is meaningless, because it involves division by zero.

On the other hand, sin(0)=0 as well, so the sinc function evaluated at zero involves 0/0. This quotient is called an indeterminant form. The logic is this: Suppose we assume that 0/0=b for some number b. then 0=0×b=0. So any value of b would do; the value of 0/0 is “indeterminant.”

Still another answer is suggested by plotting out sinc(x) near x=0 and reading the value off the graph: sinc(0) = 1.

slice_plot(sin(x) / x ~ x, bounds(x=c(-10,10)), npts=500)

Figure 27.8: To judge from this plot, sin(0)=1.

The graph of sinc() looks smooth and the shape makes sense. Even if we zoom in very close to x=0, the graph continues to look smooth. We call such functions well behaved.

Compare the well-behaved sinc() to a very closely related function (which does not seem to be so important in applied work): sin(x)x3.

Both sin(x)/x and sin(x)/x3, evaluated at x=0 involve a divide by zero. Both are indeterminate forms 0/0 at x=0. But the graph of sin(x)/x3 (see ?fig-sinc2) is not we will behaved. sin(x)/x3 does not have any particular value at x=0; instead, it has an asymptote.

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())

Figure 27.9: Zooming in around the division by zero. Left: The graph of sin(x)/x versus x. Right: The graph of sin(x)/x2. The vertical scales on the two graphs are utterly different.

Figure 27.10: Zooming in around the division by zero. Left: The graph of sin(x)/x versus x. Right: The graph of sin(x)/x2. The vertical scales on the two graphs are utterly different.

Since both sin(x)/x|x=0 and sin(x)/x3|x=0 involve a divide-by-zero, the answer to the utterly different behavior of the two functions is not to be found at zero. Instead, it is to be found near zero. For any non-zero value of x, the arithmetic to evaluate the functions is straight-forward. Note that sin(x)/x3 starts its mis-behavior away from zero. The slope of sin(x)/x3 is very large near x=0, while the slope of sin(x)/x smoothly approaches zero.

Since we are interested in behavior near x=0, a useful technique is to approximate the numerator and denominator of both functions by polynomial approximations.

  • sin(x)x16x3 near x=0
  • x is already a polynomial.
  • x3 is already a polynomial.

Remember, these approximations are exact as x goes to zero. So sufficiently close to zero,

sin(x)x=x16x3x=1+16x2

Even at x=0, there is nothing indeterminant about 1+x2/6; it is simply 1.

Compare this to the polynomial approximation to sin(x)/x3:

sin(x)x3=x16x3x3=1x216

Evaluating this at x=0 involves division by zero. No wonder it is badly behaved.

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.

Conventionally, the relationship is written

limxx0u(x)v(x)=limxx0xu(x)xv(x)

Let’s try this out with our two example functions around x=0:

limx0sin(x)x=limx0cos(x)limx01=11=1

limx0sin(x)x3=limx0cos(x)limx03x2=10  indeterminate!

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 sin(x)/x even when the plotting domain includes zero.

27.6 Drill

Part 1 Here is a function f(x):

In the Taylor polynomial approximation to f(x) centered at x=2, what will be the sign of the coefficient on the first-order term. Choose the best answer.

  1. positive
  2. zero
  3. negative
  4. no such coefficient exists in a Taylor polynomial

Part 2 Here is a function f(x):

In the Taylor polynomial approximation to f(x) centered at x=1, what will be the sign of the coefficient on the first-order term. Choose the best answer.

  1. positive
  2. zero
  3. negative
  4. no such coefficient exists in a Taylor polynomial

Part 3 Here is a function f(x):

In the Taylor polynomial approximation to f(x) centered at x=1, what will be the sign of the coefficient on the second-order term. Choose the best answer.

  1. positive
  2. zero
  3. negative
  4. no such coefficient exists in a Taylor polynomial

Part 4 Here is a function f(x):

In the Taylor polynomial approximation to f(x) centered at x=4, what will be the sign of the coefficient on the first-order term. Choose the best answer.

  1. positive
  2. zero
  3. negative
  4. no such coefficient exists in a Taylor polynomial

Part 5 Here is a function f(x):

In the Taylor polynomial approximation to f(x) centered at x=4, what will be the sign of the coefficient on the second-order term. Choose the best answer.

  1. positive
  2. zero
  3. negative
  4. no such coefficient exists in a Taylor polynomial

Part 6 Here is a function f(x):

In the Taylor polynomial approximation to f(x) centered at x=4, what will be the sign of the coefficient on the constant (zeroth-order) term. Choose the best answer.

  1. positive
  2. zero
  3. negative
  4. no such coefficient exists in a Taylor polynomial

Part 7 Here is a function f(x):

In the Taylor polynomial approximation to f(x) centered at x=3, what will be the sign of the coefficient on the second-order term. Choose the best answer.

  1. positive
  2. zero
  3. negative
  4. no such term exists in a Taylor polynomial

Part 8 Here is a function f(x):

In the Taylor polynomial approximation to f(x) centered at x=0, what will be the sign of the coefficient on the reciprocal term. Choose the best answer.

  1. positive
  2. zero
  3. negative
  4. no such term exists in a Taylor polynomial

Part 9 Here is a function g(x):

Two Taylor polynomials, centered on the same x are shown. One is fifth-order, the other is third-order. Which is which?

  1. The third-order polynomial is brown.
  2. The third-order polynomial is magenta.

Part 10 Here is a function g(x):

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 ex has an especially lovely formula: p(x)=1+x1!+x22!+x33!+x44!+

Part A In the above formula, the center x0 does not appear. Why not?

  1. Having a center is not a requirement for a Taylor polynomial.
  2. There is a center, x0=1, but terms like x0x2 were simplified to x2.
  3. There is a center, x0=0, but the terms like (xx0)2 were simplified to x2.

Exercise 27.02

Here is a Taylor polynomial:

p(x)=e+e1!(x1)+e2!(x1)2+

Part A Where is the center x0 of this polynomial?

x0=2x0=1x0=0x0=1x0=2

Part B Your roommate suggests that p(x) is a Taylor expansion of ex around x=1. Is he right?

  1. No, a polynomial does not have functions like e.
  2. Yes. The center is x0=1.
  3. Not really. The formula suggests that the center is x0=1 but the coefficients are wrong.

Exercise 27.03

Consider the function f(x)(x3)2.

Part A Using ordinary algebra, f(x) can be expanded as (x26x9). Consider p(x)=96x+x2. Is p() a Taylor polynomial expansion of f(x)?

  1. Yes, with a center at x0=0
  2. Yes, with a center at x0=3
  3. No, because there are no factorials involved

Exercise 27.04

Here’s the Taylor polynomial expansion of sin(x) about a center x0:

p(x)=1/23/22!(xx0)2+1/24!(xx0)4+

Part A Which of these is the numerical value of x0? (Hint: Remember that the coefficients involve the function and its derivatives evaluated at x0 as described in Section @ref(high-order-approx).)

π/6π/3π/2π

Problem with Differentiation Exercises/camel-sing-futon

Exercise 27.06

Consider the function f(x)sin(xπ6) and its 3rd order Taylor polynomial approximation, T(x). We will implement both in R/mosaic:

f <- makeFun(sin(x-pi/6)~x)
T <- makeFun(-.5+x*sqrt(3)/2+.25*x^2-x^3/(4*sqrt(3))~x)

In this exercise, we want to figure out the extent of the interval in which T(x) is within 0.05 of f(x). We can do this by plotting T(x) and also the two functions f(x)+0.05 and f(x)0.05.

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 x for which f(x)0.05<T(x)<f(x)+0.05. (Hint: you may need to modify the plotting commands.)

x(1.1,1,1)x(1.1,1.5)x(1.5,1.1)x(1.5,1.5)

Exercise 27.07

With very high-order derivatives, it can be awkward to use a notation with repeated subscripts, like xxxxxf(x). Another notation often encountered is f(5), where the integer in the superscript tells the order of the derivative. We will use that notation in this problem.

For a function f(x) and its derivatives f(1)(x), f(2)(x), … the Taylor polynomial p(x) centered on x0 is

p(x)f(x0)+f(1)(x0)1!(xx0)1+f(2)(x0)2!(xx0)2+

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?

  1. f(x),f(1)(x),f(2)(x),
  2. f(x0),f(1)(x0),f(2)(x0),
  3. f(x0),f(1)(x0)1!,f(2)(x0)2!,
  4. (xx0),(xx0)2,

Exercise 27.08

It is worth remembering the first couple of terms in the Taylor polynomial approximation of the sine and cosine functions.

sin(x)x123x3cos(x)112x2$$

Part A What is the order of the approximation to sin(x) given above?

First Second Third Fourth

Part B What is the order of the approximation to cos(x) given above?

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 x terms as permitted, and examining if the resulting formula makes sense. If it does, calculate the numerical value of the limit.

Example:

limx01sin(x)x2  becomes  limx01x+x3/6x=limx0(1x1+x26)

The 1 and x2/6 terms are perfectly sensible in the limit as x0, but the 1/x term implies division by zero. There is no numerical value for the limit.

a.  limx01cos(x)x

b.  limx01cos(x)x2

c.  limx0sin(x)x

Exercise 27.09

Each of the three functions graphed below is a simple power-law function that can be written [xx0]n. The three functions have different values for x0 and for n.

Part A For the extblue function, what is x0?

0 1 2 3 4 5

Part B For the extblue function, what is the order of the polynomial?

0 1 2 3 4 5


Part C For the extorange function, what is x0?

0 1 2 3 4 5

Part D For the extorange function, what is the order of the polynomial?

0 1 2 3 4 5


Part E For the extmagenta function, what is x0?

-2 -1 0 1 2 3

Part F For the extmagenta function, what is the order of the polynomial?

0 1 2 3 4 5

Exercise 27.10

At x=0, the value of xln(x) is indeterminate, having the form 0.

Using a sandbox, plot out xln(x) over the domain 0<x<12.

Part A From the graph, determine limx0xln(x(). Choose the correct answer.

-0.2 0 0.1 0.5 not well behaved

Use l’Hopital’s rule to confirm that limx0xln(x() exists. Here, the rule has the form:

$$_{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 dnorm(x). To do this, we will need the numbers

dnorm(x0),  xdnorm(x0),  xxdnorm(x0),  xxxdnorm(x0),...

Here are the functions for the derivatives

Order formula for derivative
0th dnorm(x)
1st [x]dnorm(x)
2nd [x21]dnorm(x)
3rd [3xx3]dnorm(x)
4th [3x2x4]dnorm(x)
5th [36x3+x5]dnorm(x)
6th [15x2+10x4x6]dnorm(x)
7th [15+45x315x5+x7]dnorm(x)
8th [105x2105x4+21x6x8]dnorm(x)
  1. Write a Taylor polynomial function for dnorm(x) around x0=0). To do this, you will have to evaluate each of the 9 formulas above at x=0, 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:
T_at_0 = makeFun(0.3989 + 
                   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.

  1. Plot T_at_0(x) ~ x over the domain 0x2, and pipe the result to a slice-plot of dnorm(x) ~ x so that you can compare the two plots.

  2. Define another function T_at_1() which will be much like T_at_zero() but with x0=1 and the coefficients changed to be the formulas evaluated at x=1.

  3. 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?

  1. Write a piecewise function of this form:
T <- makeFun(ifelse(abs(x) < 0.5, 
                    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.


  1. The fundamental theorem says that an order-n polynomial has n roots (including multiplicities).↩︎

  2. The mathematical background needed for those better tools won’t be available to us until Block 5, when we explore linear algebra.↩︎

  3. 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.↩︎

  4. In many French words, the sequence “os” has been replaced by a single, accented letter,  o ^.↩︎