% Licensed under the Attribution-NonCommercial-ShareAlike 2.5 [http://creativecommons.org/licenses/by-nc-sa/2.5/] license.
% If you make a derivative work, please add a credits page and list me as the original author.
% -- James Sumners <james DOT sumners AT gmail DOT com>

\documentclass[11pt]{article}
\title{Determing Accuracy Of A Taylor Polynomial In An Interval}
\author{James Sumners}
\date{\today}

%\pagestyle{empty}
%\parindent  15.mm % indent paragraph by this much
\parskip     2.mm   % space between paragraphs
\usepackage{amsmath, amsthm, amssymb} % Allows us to redefine theorem styles.

\newtheoremstyle{mythm} % Define a custom theorem style
{\topsep} % Spacing above theorem
{\topsep} % Spacing below theorem
{} % Body font
{} % Indent amount (empty = no indent, \parindent = para indent)
{\bfseries} % Theorem head font
{:} % Punctuation after theorem head
{\newline} % Space after thm head: " " = normal interword space; \newline = linebreak
{} % Thm head spec (can be left empty, meaning `normal')

\theoremstyle{mythm}% Define a new theorem that won't be numbered and has a regular typeface.
\newtheorem*{thma}{Taylor's Theorem}

\begin{document}
\maketitle

Consider the problem:

\begin{quotation}Construct a Taylor polynomial approximation that is accurate within $\frac{1}{2}\times 10^{-3}$, over
the given interval, for the function: $f(x) = e^{-x}$ where $x\in[0,1]$. Expand about the point $x_{0} = 0$.\end{quotation}

Also, recall Taylor's Theorem:\footnote{\textit{Numerical Methods and Computing, Fifth Edition} by Ward Cheney and David
Kincaid [pg. 22].}

\begin{thma} If the function $f$ possesses continuous derivatives of orders $0, 1, 2,\dots,(n+1)$ in a closed interval
$I=[a,b]$, then for any $c$ and $x$ in $I$,
\begin{equation}\label{eq:no1} f(x) = \sum_{k=0}^{n}\frac{f^{k}(c)}{k!}(x-6)^{k}+E_{n+1}
\end{equation} where the error term $E_{n+1}$ can be given in the form
\begin{equation}\label{eq:no2} E_{n+1} = \frac{f^{(n+1)}(\xi )}{(n+1)!}(x-c)^{n+1}
\end{equation} Here $\xi$ is a point that lies between $c$ and $x$, and depends on both.
\end{thma}

Our goal is to determine how many terms in a Taylor polynomial are required to meet the desired accuraty of
$\frac{1}{2}\times 10^{-3}$. To do this, we must determine when Eq.~(\ref{eq:no2}) is greater than or equal to $\frac{1}{2}\times
10^{-3}$. Essentially, we want to find the maximum values for $|f^{(n+1)}(\xi)|$ and $|(x-c)^{(n+1)}|$ in our interval.
Let's begin by examining the first few derivatives of $e^{-x}$.
\begin{eqnarray*}
f'(x) = -e^{-x} & f''(x) = e^{-x} \\
f^{3}(x) = -e^{-x} & f^{4}(x) = e^{-x}
\end{eqnarray*}

Of course, the derivative of $e^{x}$ is $e^{x}$ and the derivative of $e^{-x}$ is just going to alternate between
positive and negative values of $e^{-x}$. Thus, $e^{-1} = 0.367879$ and $e^{-0} = 1$ giving us the maximum value of
$|f^{(n+1)}(\xi)|$ at $\xi = 0$. And so Eq.~(\ref{eq:no2}) becomes:\\
\begin{equation}\label{eq:no3} E_{n+1} = \frac{1}{(n+1)!}(x-c)^{n+1}\end{equation}

Now we must maximize $|(x-c)^{n+1}|$. In this problem it is simple. We are expanding about $x_{0} = 0$ so $c = 0$ and
$x$ ranges from 0 to 1. So, it doesn't matter what the value of $n$ is; the maximum value of $(x-c)^{n+1}$ is always
going to be 1 on our interval. From Eq.~(\ref{eq:no3}) we have:\\
\begin{equation}\label{eq:no4} E_{n+1} = \frac{1}{(n+1)!}(1)^{n+1} = \frac{1}{(n+1)!}\end{equation}

Which gives us the equation:\\
\begin{equation*}\frac{1}{(n+1)!} \leq \frac{1}{2}\times10^{-3}\end{equation*}

Solving this equation by hand can be tedious. Using technology to solve this equation is a much more judicious way to
solve this inequality. For example, on a TI-89 one could enter ``\texttt{$0 \rightarrow n$:While $\frac{1}{(n+1)!} > 
\frac{1}{2}*10^{-3}$:n+1 $\rightarrow$ n:EndWhile:Disp n:DelVar n}". The $n$ displayed at the end of the loop execution
will be the number of terms necessary for a Taylor polynomial approximation of $e^{-x}$ accurate to
$\frac{1}{2}\times10^{-3}$. In this case, $n = 6$ and $T_{6}(x) = 1 - x + \frac{x^{2}}{2} - \frac{x^{3}}{6} +
\frac{x^{4}}{24} - \frac{x^{5}}{120} + \frac{x^{6}}{720}$. Thus:\\
\begin{eqnarray*}
T_{6}(0.5) \approx 0.6065321181\\
e^{-0.5} \approx 0.6065306597
\end{eqnarray*}

\end{document}
