Taylor polynomials and the error bound · Mathematics… | StemPy Lab
Course 15.3·Lesson 2 of 3
Taylor polynomials and the error bound
A Taylor polynomial of degree n matches a function and its first n derivatives at one point. Its coefficients are k!f(k)(a)
Lesson 2 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
What you will be able to do
build the Taylor polynomial of a function about any point from its derivatives;
write the Maclaurin series of ex, sinx, cosx, 1−x1 and ln(1+x) with their intervals of convergence;
bound the error of a Taylor polynomial with the Lagrange error bound and, where it applies, with the alternating series bound.
Fitting a polynomial to a curve
A calculator finds sin0.5 by adding a few terms of a long sum. Where does the sum come from? Start with a curve y=f(x) and a point x=a. We look for a polynomial that has the same value as f at a, the same slope, the same bend, and so on.
Try f(x)=ex at a=0. Every derivative of ex is ex, which equals 1 at 0. Suppose P(x)=c0+c1x+c2x2+c3x3.
P(0)=c0, so c0=1.
P′(0)=c1, so c1=1.
P′′(0)=2c2, so c2=21.
P′′′(0)=6c3, so c3=61.
The kth derivative of ckxk at 0 is k!ck. So to match f(k)(0) we take ck=k!f(k)(0).
The Taylor polynomial and the Taylor series
The Taylor polynomial of degree n of f about x=a is
If we let n grow without end we get the Taylor series. When a=0 it is called the Maclaurin series. A-Level and IB books use the name Maclaurin series for this case too. Remember that 0!=1 and that k! means k×(k−1)×⋯×1.
The five series to know
Each of these is a Maclaurin series, with x in radians for the trigonometric ones.
ex=1+x+2!x2+3!x3+⋯=n=0∑∞n!xn, for every real x.
sinx=x−3!x3+5!x5−⋯=n=0∑∞(2n+1)!(−1)nx2n+1, for every real x.
cosx=1−2!x2+4!x4−⋯=n=0∑∞(2n)!(−1)nx2n, for every real x.
1−x1=1+x+x2+⋯=n=0∑∞xn, for −1<x<1.
ln(1+x)=x−2x2+3x3−⋯=n=1∑∞n(−1)n+1xn, for −1<x≤1.
The first three have radius ∞, because their coefficients contain a factorial. The last two have radius 1. The series for ln(1+x) includes the endpoint x=1, where it is the alternating harmonic series, and excludes x=−1, where it becomes the negative of the harmonic series.
Where the sine series comes from
The derivatives of sinx at 0 go round in a cycle of four: sin0=0, cos0=1, −sin0=0, −cos0=−1, and then the cycle repeats. So the even-power coefficients are zero. The odd ones are 1!1,3!−1,5!1,… This gives the series above.
The graph of y = sin x from x = -7 to 7 in blue, with the Taylor polynomials of degree 1, 3, 5 and 7 about 0 in orange, green, violet and red. The degree 1 line is straight. Each higher polynomial stays close to the sine over a wider interval around 0 before it turns away steeply up or down. The labels name each degree.
A Taylor polynomial about a point other than 0
Find the Taylor polynomial of degree 2 of f(x)=x about a=4.
To estimate 4.4 put x−4=0.4. Then P2=2+0.1−0.0025=2.0975. A calculator gives 2.09762, so the estimate is good to about 0.0001. You could not do this from the Maclaurin series, because x has no Maclaurin series: its derivative is not defined at 0.
Why the interval matters
The series of ln(1+x) has radius 1. Inside the interval the polynomials fit the curve better and better as the degree grows. Outside it they fit worse and worse, however many terms you take.
The graph of y = ln(1 + x) from x = -0.9 to 2 in blue, with three Maclaurin polynomials of degree 2, 5 and 10. Between x = -0.6 and x = 1 the polynomials of higher degree lie closer to the blue curve. For x above 1 the polynomials of higher degree move far from the curve. A vertical dashed line marks x = 1, the end of the interval. The degree 10 polynomial turns steeply downwards soon after x = 1 and the degree 5 polynomial climbs away upwards.
How big is the error?
An estimate is only useful when you know how good it is. The remainder is Rn(x)=f(x)−Pn(x). The Lagrange error bound says: if ∣f(n+1)(t)∣≤M for every t between a and x, then
∣Rn(x)∣≤(n+1)!M∣x−a∣n+1.
AP Calculus BC calls this the Lagrange error bound. A-Level and IB books state the same result by writing Rn(x)=(n+1)!f(n+1)(c)(x−a)n+1 for some number c between a and x. Bounding ∣f(n+1)(c)∣ by M gives the bound.
Example. Estimate e0.3 with the polynomial of degree 3 about 0.
P3(0.3)=1+0.3+20.09+60.027=1.3495.
The fourth derivative of ex is ex. For t between 0 and 0.3 it is below 1.35, so take M=1.35.
The bound is 4!1.35(0.3)4=241.35×0.0081≈0.00046.
The true value is 1.349859, so the true error is 0.00036. It is below the bound, as it must be.
The graph of the error |e^x - P3(x)| of the degree 3 Maclaurin polynomial of e^x for x from 0 to 1, in blue, together with the Lagrange bound e x^4 / 24 in orange. The blue curve always lies below the orange curve, and both start at 0 and grow like x to the fourth. The values at x = 1 are about 0.052 for the error and 0.113 for the bound.
How many terms? To estimate e itself to within 0.001, use a=0, x=1 and M=3, since e<3. We need (n+1)!3<0.001, that is, (n+1)!>3000. Now 6!=720 is too small and 7!=5040 is enough. So n+1=7 and n=6.
The alternating series bound
Some Taylor series alternate in sign with terms that shrink to zero. The series for sinx and cosx do this for any fixed x once n is large enough, and so does the series for ln(1+x) for 0<x≤1. For such a series, you may use the rule from the last course: the error is no bigger than the first omitted term.
Example. Estimate sin0.5 with the terms up to x3.
0.5−60.53=0.5−0.020833=0.479167.
The first omitted term is 1200.55=0.00026.
So the error is at most 0.00026. The true value is 0.479426, and the true error is 0.000259.
The alternating bound is often sharper than the Lagrange bound and easier to use. But it needs a series that alternates with shrinking terms. The Lagrange bound works for any function whose derivatives you can bound.
Practise with new numbers
Try it in Python
The program builds Taylor polynomials of sinx of degree 1,3,5,7 at x=0.8. For each one it prints the actual error beside the Lagrange bound with M=1.
Common mistakes
Forgetting the factorial. The coefficient is k!f(k)(a). Without the k! the polynomial does not match the function.
Using x instead of x−a. About a point a=0 the powers are of (x−a).
A wrong order in the error bound. For a polynomial of degree n the bound uses the (n+1)th derivative and (n+1)!.
Taking M at the wrong place.M must bound the derivative on the whole stretch between a and x, not only at one end.
Using the alternating bound for any series. The terms must alternate and shrink to zero.
Trusting a series outside its interval. The series of ln(1+x) does not give ln3 at x=2, because 2 is outside the interval.
Remember these
Pn(x)=∑k=0nk!f(k)(a)(x−a)k, and for a=0 it is the Maclaurin polynomial.
ex, sinx, cosx have radius ∞. 1−x1 and ln(1+x) have radius 1.
Lagrange error bound: ∣Rn(x)∣≤(n+1)!M∣x−a∣n+1.
For an alternating series with shrinking terms, the error is at most the first omitted term.
Check yourself
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
Write the first three nonzero terms of the Maclaurin series of cos3x.
Find the Taylor polynomial of degree 2 of lnx about a=1, and use it to estimate ln1.2.
Use P3(x)=x−6x3 for sin0.2. Give a Lagrange bound on the error with M=1.
How large must n be so that the Maclaurin polynomial Pn(1) of ex estimates e with error below 0.01? Use M=3.
A student puts x=2 in the Maclaurin series of 1−x1 and gets 1+2+4+8+⋯. She says this equals −1. Is she right?
References
OpenStax, Calculus Volume 2, Chapter 6, sections 6.3 on Taylor and Maclaurin series and 6.4 on working with Taylor series.
College Board, AP Calculus AB and BC Course and Exam Description, Unit 10, on Taylor polynomials and the Lagrange error bound.
Enroll free in Power Series and Taylor Series
Every lesson is open to read. Enrolling also lets you:
Mark lessons done and carry on where you stopped.
Take the tests of this lesson and its course.
Count the course towards the certificate for its chapter.
the Maclaurin series. The Lagrange error bound and, for alternating series, the first omitted term tell you how far the polynomial can be from the function.
about 35 min1 simulation2 practice questions1 Python program5 questions to check yourself
This lesson is free to read. Enroll free to keep your place and take the tests.