Computer Lab #3: Taylor Polynomials

advertisement
Computer Lab #3: Taylor Polynomials
Goal: The purpose of this lab is to study W∣α Taylor polynomials for some functions and to see
how they approximate the original function. Using the computer we can do this of higher degree,
and for more functions than we could do by hand. In this study we will be guided by the following
general questions:
• What happens to the Taylor polynomial when its order increases?
• For which values of x is Tn (x) close to f (x)?
• How do we measure the difference between Tn (x) and f (x)?
Commands Introduced: taylor, Piecewise
You will notice the following three properties, which are a recurring theme in this lab, and
You might have noted already that W∣α will often
will find an explanation in the error term estigive you a series approximation of a function. We
mate, which will be covered in the next class lecwill now look at this explicitly. The command to
ture:
obtain a series approximation of f (x) of degree
n centered at the point a is
• The Taylor polynomials provide an excel-
Topic #1: Some Taylor polynomials
taylor f(x) at a order n
lent approximation close to the center, but
become worse the further from the center.
=
,
• Taylor polynomials of higher degree approximate f (x) better.
so for example
taylor exp(-x^2) at 0 order 4
• The flatter the function is, the better the
approximation around the center. (Be
aware that the default plotting intervals
changed between the examples.)
=
W∣α will give you a plot of the first few taylor
polynomials. (You can use the general shape to
determine which is which for low degree polynomials.)
Question #1 Remember that your write up
Lets look at this function for another center should be proper text, not just a collection of
and for higher order:
Yes/No’s or numbers.
taylor exp(-x^2) at 2 order 6
=
a) Examine the Taylor polynomials of cos(x)
centered at a = 0 over the interval
[−2π, 2π]. What happens as the order n
increases? When do the graphs become
identical?
Note that the plot by default is just for small
degrees, but you can use the button More terms
to have it display further polynomials. This tool
can also be used to identify which polynomial is
which, something that you should indicate in the
graphs in your lab report.
b) Why is the Taylor polynomial of order 2
equal to the Taylor polynomial of order 3?
1
c) Start over with Taylor polynomials for
In practice, the quantity (∗) is a function of
f (x) = cos(x) centered at a = 2 and for x and by plotting it we can estimate its largest
an interval of width 4π centered at a, i.e. value. Lets do this for cos(x) and its Taylor poly[2 − 2π, 2 + 2π]. When do the graphs seem nomial of order 4. We get this polynomial as
to be identical?
taylor cos(x) order 4
=
d) If you consider the larger interval [2 −
2
4
and read off that it is 1 − x2 + x24 . We now plot
3π, 2 + 3π] and plot Taylor polynomials
centered at a = 2, for what order Tay- the difference of function and Taylor polynomial:
lor polynomials do the graphs seem to be
plot abs(cos(x)-(1-x^2/2+x^4/24)),
identical?
x=-2..2
=
The abs command here stands for absolute
e) In words, describe how the graph of
value.
the Taylor polynomial is approaching the
Now we can see that the graph of the funcgraph of f .
tion (∗) is always smaller than 0.09 since the upf) Give a geometric interpretation (i.e what
per bound of the range of this interval is less than
type of function are you graphing) of T1
0.09. Therefore we claim that the error between f
when a=0 and relate it to the graph of
and T4 over the interval [−2, 2] is less than 0.09.
cos(x).
If we rescale the y-axis
plot abs(cos(x)-(1-x^2/2+x^4/24)),
x=-2..2,y=0..0.005
=
Topic #2: Computing the error
In the previous exercises, we claimed that f was
close to Tn when the graphs overlapped. We will
try to be more precise about the closeness between these two graphs.
We know how to measure the distance between the values of f and Tn at a point x. This
distance is
∣ f (x) − Tn (x)∣ .
we see that for x ∈ [−1, 1] we even have an
error < 5 ⋅ 10−3 = 0.005.
(Indeed the plot of Taylor polynomials shows
that the graphs of f and T4 over the interval [2,2] are very close and therefore that the error
between f and T4 should be small.
Question #2 In this question we will look at
1
On the other hand, f and Tn are defined over
and its Taythe distance between f (x) =
an interval [a, b] and for some choices of x, this
1 + x2
distance may be large while for some other val- lor polynomials centered at 0.
ues of x this distance may be small. What do we
a) Using the geometric series write a power
do when have to consider a whole range of values
series representation for f (x).
for x? Take the largest one!
b) What is the interval of convergence of this
power series representation of f ?
Definition The error between f and its n-th
c) Use the taylor command to find the Tayorder Taylor polynomial over the interval [a, b]
lor polynomials of order 1, 2, 3, 4, and 5 at
is the maximum value of
a = 0. (Make sure you give the command
with at 0, as W∣α otherwise will not plot
∣ f (x) − Tn (x)∣
(∗)
but calculate other series.) How are they
related to the power series?
when x belongs to [a, b].
2
d) Plot the Taylor polynomials of order up to near x = 0, we expect that its derivative (and
8. Make sure you label the polynomials maybe all or a bunch of its derivatives) to be zero
correctly in the graph.
at x = 0. This is what we will check.
We calculate the derivative using
e) Using a plot of the difference ∣ f (x)−Tn ∣ on
the interval [−0.5, 0.5], estimate the maximal error of the Taylor approximation for
n = 4 and n = 8 on this interval.
d/dx Piecewise[{{0,x<=0},
{exp(-1/x^2),0<x}}]
=
f) The function f is smooth at x = −1 and x =
You see that the derivative also has value 0 at
+1 (continuous, differentiable, etc.) but the
′
Taylor polynomials are doing something 0 and limit limx→0 f (x) = 0, so the derivative is
funny at those points. Can you explain continuous (and indeed differential again).
We can now look at the second derivative:
why the Taylor polynomials might be acting funny at or near x = −1 and x = +1?
d^2/dx^2 Piecewise[{{0,x<=0},
{exp(-1/x^2),0<x}}]
=
Topic #3: A Function and its Taylor
Polynomials
Again we observe that this function is perfectly
well defined (as indeed are all the further
We will now study a very famous function. We
won’t give the punch line away immediately, so derivatives). We can therefore compute its Taylor polynomial centered at a = 0. The obvious
please bear with us.
1
Consider the function g(x) ∶= e − x 2 . This command
function is not defined for x = 0 but can be made
taylor Piecewise[{{0,x<=0},
continuous by setting it to limx→0 g(x) = 0 for
{exp(-1/x^2),0<x}}]
=
x < 0. Thus we define the function
e− x2
f (x) = {
0
1
x =/ 0
x <= 0
however will give a somewhat strange answer
– a series evaluated at ∞ (to avoid the problem
at 0). We are thus to have to compute the Taylor
We define this function in W∣α using a piecepolynomial the hard way, by evaluating derivawise definition:
tives.
Piecewise[{{0,x<=0},
{exp(-1/x^2),0<x}}]
=
Question #3
So, for example to graph this function over
a) Compute the value of f (n) (0) for n =
the interval [−5, 5], type
3, 4, 5 by taking higher derivatives. Make
plot Piecewise[{{0,x<=0},
a guess for the value of f (20) (0) and check
{exp(-1/x^2),0<x}}], x=-5..5
=
it.
You see that the setting f (0) ∶= 0 was perfectly justified. Notice also how flat the graph of
f is near x = 0. Now try graphing it over the interval [−1, 1]. Because the graph of f is so flat
b) Using your guess from a), write down the
Taylor polynomials and the Taylor Series
for f centered at a = 0. Do the Taylor polynomials approach f as n increases?
3
c) (This problem as well as the next should
be answered only after the next lecture –
the error estimate for Taylor polynomials.) Describe the behavior of the derivatives f (n) (x) for 0 < x < 0.2 and n =
1, 2, 3, 10, 20. What does this mean for the
error estimate if we calculated instead a
Taylor polynomial centered at a value a >
0.
d) Plot the Taylor polynomials of order up to
6 centered at a = 1, centered at a = 0.5 and
centered at a = 0.1. (Make sure you indicate what is the polynomial of degree 6!)
Explain the behavior in view of the result
at c).
4
Download