Section 3 Taylor polynomials
¶Subsection 3.1 Taylor's theorem
In calculus, you should have learned that an infinitely differentiable function possesses a representation in the form of an infinite power series. You are probably familiar with
Power series are an incredibly powerful tool for approximating functions, and they occur all over numerical mathematics. Typically, instead of using an infinite series, we truncate at a particular term, getting a polynomial that approximates the function rather than a series that is the function (where it converges). The general theorem that describes how to get a polynomial approximation for a function is called Taylor's theorem.
Theorem 3.1.
Let \(f\) be a function so that \(n + 1\) derivatives of \(f\) exist on an interval \((a, b)\) and let \(x_0 \in (a,b)\text{.}\) Then for each \(x \in (a,b)\text{,}\) there exists a constant \(c\) strictly between \(x\) and \(x_0\) such that
The first part of the equation above is the \(n\)th order Taylor polynomial for \(f\) at \(x_0\), and we use the notation
The second part is called the remainder term for \(T_n\) at \(x_0\text{,}\) and we use the notation
You can think of the remainder term as containing the difference between \(f\) and \(T_n\text{.}\) We don't usually know the value of \(c\) for a given \(x_0\text{,}\) but we can the remainder term to put an upper bound on the worst possible error for a given Taylor approximation of \(f\) on \((a, b)\text{.}\)
So what's the upshot? Unwrapped from sigma notation, essentially any well-enough behaved function can be approximated at a point \(x_0\) with a polynomial that is easy to calculate. That is, for values of \(x\) near \(x_0\text{,}\)
and the worst that the approximation will be is the maximum value of \(R_n(x)\) near \(x_0\text{.}\)
Subsection 3.2 What is a Taylor approximation good for?
An obvious question should occur to you: why do we care about Taylor series and polynomials? The short answer is that Taylor polynomials behave much like their parent functions “near” the point of expansion. By including more terms, we typically expect to get a better approximation of the original function and a larger interval on which the approximation is well-behaved. A classical example of this phenomenon can be seen in the Taylor polynomials for \(\sin x\) near \(x_0 = 0\text{.}\)
The idea of replacing a function with a polynomial built from its derivatives is a powerful computational technique. Indeed, if we're working with approximations, we often need not even compute formulae for the derivatives but instead work with difference quotients. This will require that we have a firm understanding of how error accumulates, which will be discussed in a future lecture.
Subsection 3.3 Coding functions in Octave
Let's begin by talking a bit about how to use functions in Octave. Suppose that we are interested in the 3rd Taylor polynomial for the function \(f(x) = e^x\) at \(x_0 = 0\text{.}\) A bit of computation will tell you that
First, we'll need to define the function \(T_3\) so that we can use it like a function - we want to be able to plot and evaluate it at various points. To do so, we'll use the inline
command.
Once we have the function defined, we can evaluate it anywhere.
A standard technique that we need to be comfortable with is evaluating functions on arrays (that is, lists of numbers). Here are some example arrays.
An incredible useful feature of Octave/Matlab is the ability to feed an array into a function. However, Octave assumes that we want matrix operations unless we tell it that we want to work entry by entry. The way we do that is to put a . before any operation that could be interpreted as a matrix operation to force Octave to work entrywise.
Plotting in Octave seems complicated, but really just exposes how mathematical software generates plots in general. Suppose that we want to compare the function \(f(x) = e^x\) with the Taylor polynomial \(T_3\text{.}\) Our goal is plot both functions on the same set of axes. A useful command for this is plot
.