Taylor Polynomial Demo

Recall that the $n^{\mathrm{th}}$ order Taylor polynomial for $f(x)$ based at $x=a$ is \[ P_n(x) = f(a) + f'(a)(x-a) + \dfrac{f''(a)}{2}(x-a)^2 + \dfrac{f'''(a)}{3!} + \cdots + \dfrac{f^{(n)}(a)}{n!}(x-a)^n \] This is the "best" $n^{\mathrm{th}}$ order approximation of $f(x)$ based at $x=a$. Specifically, $f(a)=P_n(a)$, $f'(a)=P_n'(a)$, ..., $f^{(n)}(a)=P_n^{(n)}(a)$. This means that $P_n(x)$ and $f(x)$'s values and derivative values match at $x=a$.

Given a function (specified in the box labeled "$f(x)=$"), this demo plots $y=f(x)$ in blue (if the "Plot $f(x)$?" box is checked) and a dot at $(x,y)=(a,f(a))$ (according to the value of $a$ specified in the box). It then computes the Taylor polynomials of $f(x)$ based $x=a$ up through order $N$ (as specified on the slider bar).

The plot then shows $P_0(x),\dots,P_N(x)$ all together if the "Plot?" drop down box has "All orders" selected. If "Only highest order" is selected, only $P_N(x)$ will be displayed. If "Animation" is selected, an animation cycling through $P_0(x)$, $P_1(x)$, ..., $P_N(x)$ will be generated.

By default $P_N(x)$ (the $N^{\mathrm{th}}$ order Taylor polynomial of $f(x)$ at $x=a$) is displayed below the plot. This can be turned off with the appropriate checkbox. There is also a checkbox which allows you to display the first $N$ derivatives of $f(x)$. This is turned off by default. Finally, the "Plot domain" box allows you to adjust the plot window domain.

Several built in demos (with preset function, $a$ value, and plot domain) are provided in a drop down list. If you change a box entry, simply click outside the box to have Sage recompute the plots and displayed values.

The computation above is powered by SageMath. The Sage code is embedded in this webpage's html file. To view the code instruct your browser to show you this page's source. For example, in Chrome, right-click and choose "View page source".