I have updated my old code for drawing on the HTML canvas. (The old code, used in the TIME III Conference Presentation, is still available at graph.js.) If you have saved the old version of this web page, you can discard it.
Now the code is re-factored and split among several files:
LaTeX is now based on the most recent (and externally loaded) MathJax. The code we worked on in class is located in two files with self-descriptive names: cos.js and exp.js.
Suppose $n$ is a non-negative integer, $\ U$ is an open interval of the real number line, and $x_0 \in U$. Whenever a function $f$ is defined and continuously differentiable $n+1$ times on $U$, we can write the following identity for any other $x \in U$:
$$ \color{builtin} f( x ) \color{normal} = \color{taylor} \displaystyle \sum_{ i = 0 }^{ n } \frac{ 1 }{ i \ ! } \cdot { \left( \frac{ d }{ d \ t } \right)^{ i } \ {\rule[-25px]{1px}{60px}} }_{ \ t = x_0 } f( t ) \cdot ( x - x_0 )^i \color{normal} + \color{error} \frac{ 1 }{ n \ ! } \displaystyle \int_{ t = x_0 }^{x} \left( \frac{ d }{ d \ t } \right)^{ n + 1 } f( t ) \cdot ( x - t )^n \ d \ t \color{normal} .$$The sum is called the $ \color{taylor} \text{Taylor polynomial} $ of $f$ at $x_0$. We view it as the approximation of $ \color{builtin} f( x ) \color{normal} $, so that the integral is the $ \color{error} \text{error term} $ of that approximation.
It turns out that in many cases:
In those cases, the $ \color{taylor} \text{Taylor polynomial} $ can be used for approximating $ \color{builtin} f( x ) \color{normal} $ — perhaps only for the values of $x$ sufficiently close to $x_0$ — with an arbitrary, and guaranteed, precision $\varepsilon > 0$.
When used for $f( x ) = \cos( x )$ and $x_0 = 0$, the general $ \color{taylor} \text{Taylor polynomial} $ approximation turns into
$$ \color{builtin} \cos( x ) \color{normal} = \color{taylor} \displaystyle \sum_{ j = 0 }^{ k } \frac{ ( -1 )^j }{ ( 2j ) \ ! } \cdot x^{2j} \color{normal} + \color{error} \frac{ 1 }{ ( 2k ) \ ! } \displaystyle \int_{ t = 0 }^{x} \left( \frac{ d }{ d \ t } \right)^{ 2k + 1 } \cos( t ) \cdot ( x - t )^{ 2k } \ d \ t \color{normal} $$The size of the $ \color{error} \text{integral error term} $ can be estimated from above:
$$ \left| \ \color{error} \frac{ 1 }{ n \ ! } \displaystyle \int_{ t = 0 }^{x} \left( \frac{ d }{ d \ t } \right)^{ n + 1 } \cos( t ) \cdot ( x - t )^{ n } \ d \ t \color{normal} \ \right| \le \color{estimate} \frac{ \left| x \right|^{ n + 1 } }{ ( n + 1 ) \ ! } \color{normal} .$$The $ \color{estimate} \text{estimate of the error term} $ (and thus the $ \color{error} \text{error term} $ itself) converges to zero for any real $x$:
$$ \lim_{ n \rightarrow \infty } \color{estimate} \frac{ \left| x \right|^{n + 1} }{ ( n + 1 ) \ ! } \color{normal} = 0 .$$These facts provide the basis for computing $ \color{builtin} \cos( x ) \color{normal} $ with an arbitrary guaranteed precision* $\varepsilon > 0$, as done in the source code of this HTML page. To see a demonstration of this computation, press the "Show" button below. To start from scratch, press the "Reset" button or refresh the page.
When used for $f( x ) = e^x$ and $x_0 = 0$, the general $ \color{taylor} \text{Taylor polynomial} $ approximation turns into
$$ \color{builtin} e^x \color{normal} = \color{taylor} \displaystyle \sum_{ i = 0 }^{ n } \frac{ 1 }{ i \ ! } \cdot x^{i} \color{normal} + \color{error} \frac{ 1 }{ n \ ! } \displaystyle \int_{ t = 0 }^{x} e^t \cdot ( x - t )^{ n } \ d \ t \color{normal} .$$The size of the $ \color{error} \text{integral error term} $ can be estimated from above:
$$ \left| \ \color{error} \frac{ 1 }{ n \ ! } \displaystyle \int_{ t = 0 }^{x} e^t \cdot ( x - t )^{ n } \ d \ t \color{normal} \ \right| \le \color{estimate} \frac{ \max\left( 1, 3^{ \left\lceil \left| x \right| \right\rceil } \right) \cdot \left| x \right|^{ n + 1 } }{ ( n + 1 ) \ ! } \color{normal} .$$The $ \color{estimate} \text{estimate of the error term} $ (and thus the $ \color{error} \text{error term} $ itself) converges to zero for any real $x$:
$$ \lim_{ n \rightarrow \infty } \color{estimate} \frac{ \max\left( 1, 3^{ \left\lceil \left| x \right| \right\rceil } \right) \cdot \left| x \right|^{n + 1} }{ ( n + 1 ) \ ! } \color{normal} = 0 .$$These facts provide the basis for computing $ \color{builtin} e^x \color{normal} $ with an arbitrary guaranteed precision* $\varepsilon > 0$, as done in the source code of this HTML page. To see a demonstration of this computation, press the "Show" button below. To start from scratch, press the "Reset" button or refresh the page.