\magnification=\magstep1
\centerline{Mathematics 132 -- Calculus for Physical and Life Sciences 2}
\centerline{Lab Day 4: Visualizing Convergence of Taylor Series, Approximations}
\centerline{April 11, 2008 -- Lab Writeups due in class on Monday, April 21.}
\bigskip
\noindent
{\it Goals}
\bigskip
In today's lab will use Maple to compute Taylor polynomials, 
and use graphical and numerical methods to understand the 
{\it convergence} of Taylor series. 
\bigskip
\noindent
{\it Background}
\bigskip
Recall from class on Wednesday that if
$f$ is a function that has derivatives of all orders, then its
{\it Taylor series} at $x = a$ is 
$$\sum_{n=0}^\infty {f^{(n)}(a)\over n!} (x-a)^n$$
and provided that this series converges on some interval,
it defines a function whose $n$th derivative at $x = a$ is the
same as the $n$th derivative of $f(x)$ for all $n$.  
If we take the partial sums of the Taylor series, we
obtain {\it Taylor polynomials}.  
There is exactly one polynomial $p_k(x)$
of degree $\le k$ whose first $k$ derivatives at $x = a$
are the same as the corresponding derivatives of $f$ at $x = a$.
The {\it Taylor polynomials} of $f$ at $x = a$ are 
computed by the formula:
$$
p_k(x) = f(a) + f'(a)(x-a) + {f''(a)\over 2!}(x-a)^2 + 
{f'''(a)\over 3!}(x-a)^3 + \cdots + {f^{(k)}(a)\over k!}(x-a)^k.
$$


\bigskip
\noindent
{\it Taylor Polynomials in Maple}
\bigskip
Maple has a ``built-in'' function called  {\tt taylor} that can 
be used to compute Taylor polynomials of functions.  The general
format is
\medskip
\centerline{\tt taylor(f(x),x=a,d);}
\medskip
\noindent
where $f(x)$ is the function to be approximated, $a$ is the 
$x$-value where the Taylor polynomials will be expanded, and 
$d \ge 1$ is an integer.

For example, try entering the following command which computes the 
5th degree Taylor polynomial for $f(x) = e^x$
at $a = 0$
\medskip
\centerline{\tt taylor(exp(x),x=0,6);}
\medskip
\noindent
Note two things:
\medskip
\item{(1)} The output
$$
1 + x + (1/2)x^2 + (1/6)x^3 + (1/24)x^4 + (1/120)x^5 + O(x^6)
$$
is a polynomial, plus another term.  The other 
term -- $O(x^6)$ -- is intended to describe 
the size of the error if we use this polynomial
to approximate $e^x$.  The way to interpret this is 
that the error will go to zero like (a constant times) $x^6$
(at least) in the limit as $x \to 0$.  
To get rid of the error term, you can ``nest'' the  {\tt taylor}
command inside a  {\tt convert} command like this:
\medskip
\centerline{\tt convert(taylor(exp(x),x=0,6),polynom);}
\item{}
Try this and note the output.  {\it You should use this convert
step every time you want just the Taylor polynomial, without
the error term.}
\item{(2)} The 6 in the Taylor command is {\it one more than}
the degree of the polynomial.  To get the $n$th degree polynomial,
you will {\it always want to take d = n + 1} in the Maple command.
{\it This is one case where you don't want to ask ``why?''  Just
accept that this is the way Maple is set up!}
\bigskip
\noindent
{\it Lab Questions}
\bigskip
\noindent
(A)  In this question, you will generate plots of $cos(x)$, 
together with its Taylor polynomials of degrees $n = 2,4,6,8,10$
at $a = 0$ and visualize what is happening as more and more
terms are added into the Taylor polynomials.
\medskip 
\item{(1)} First plot $\cos(x)$ and it Taylor polynomial of degree
2 together on the same axes with $-\pi \le x \le \pi$.  You 
can use these commands, for instance, first to compute the 
Taylor polynomial, assign it the name {\tt p2},
then plot it with the cosine function:
\medskip
\centerline{\tt p2 := convert(taylor(cos(x),x=0,3),polynom);}
\centerline{\tt plot([cos(x), p2],x=-Pi..Pi,color=[blue,red]);}
\medskip
\item{} {\it Notes:} 
\itemitem{a.}  The $\cos(x)$ will be the blue graph and the 
polynomial will be the red graph -- the colors match the order
in the list of functions.  
\itemitem{b.} There is no $(x)$ after the {\tt p2} in the
plotting command; we computed the Taylor polynomial as an expression
in the command before, assigned it to the symbolic variable $p2$
and then used that expression in the plot command.  
\itemitem{c.} {\it When you hand in your lab write-ups, since
you will probably be printing out your work on a black and white
printer, please put in labels by hand showing which graph is which.} 

\item{(2)}  Now plot the absolute error function:  $|\cos(x)-p_2(x)|$.
(In Maple, the absolute value function is called {\tt abs}.)
What is the largest difference between $\cos(x)$ and
$p_2(x)$ on this interval?

\item{(3)} Repeat part (1) for the Taylor polynomial of degree 4 of 
$\cos(x)$ at $a = 0$.  

\item{(4)}  Does using the fourth degree polynomial to 
approximate $\cos(x)$ seem to yield better 
results than using the polynomial of degree 2?  For instance, 
is the absolute error for this polynomial smaller than the absolute
error for $p_2(x)$ on the whole interval?

\item{(5)} Repeat parts (1) and (2) 
for the Taylor polynomials of degree 6, 8, 10 of $\cos(x)$
at $a = 0$.  When you graph the polynomials of degree 8 and 10 together
with the cosine function, you may actually only see one graph
on the interval $-\pi \le x \le \pi$.  What does
that mean?  Try plotting a bigger range of $x$-values until you 
see the graphs start to ``split apart.''  When does that happen for the degree
8 polynomial?  When for the degree 10 polynomial?
\bigskip
\noindent
(B)  Now, consider the function $f(x) = \ln(1+x)$,
expanding around $a = 0$ again.  
\medskip
\item{(1)}  Plot the Taylor polynomials
of degrees 1, 2, 3, 4, 5 and the function on the interval $-1 < x < 1$.

\item{(2)}  For each degree, find an interval where the Taylor polynomial of that
degree approximates $f(x)$ to within $10^{-3}$ -- that is:  
$|f(x) - p_n(x)| < 10^{-3}$ for all $x$ in the interval.  
How do the intervals change as $n$ increases?  For instance, 
does it seem that the interval will grow to 
arbitrary length as $n$ increases, or is there a ``limit'' to 
its size on one end or the other?

\bigskip
\noindent
{\it Lab Writeups due:} In class on Monday, April 21.
\end
