Figure | Problem | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Find a Taylor polynomial that will calculate the sin(x) for any input x to within an error of 0.000001 (one millionth). |
|||||||||||||||||||||||||
Step | Equation | Explanation | ||||||||||||||||||||||||
1 |
The Taylor polynomial of order (not degree) n approximating a function f(x) is given by the formula at left. Notice that the polynomial is a function of x but also depends on the (fixed) point of expansion x = a. The point x = a should be chosen so that functional and derivative values are known at that point. |
|||||||||||||||||||||||||
2 |
|
The error between the polynomial and the function is given by the difference between the actual functional value and the polynomial value. Because the functional value is not actually known (that's why we are trying to estimate it!), the Taylor Remainder Formula (given at left) can be used to determine error estimates. |
||||||||||||||||||||||||
3 |
In addition, using the symmetry and periodicity of the sine function, we only need to know the values on the interval [0, π/2] to determine the sine values for all the real numbers. Thus, let's expand sin(x) on [0, π/2] to the desired error. |
|||||||||||||||||||||||||
4 |
The Remainder Theorem states that a result at x would be exactly known if the value of c (a < c < x) were known. Examining the "worst case" selection of the value c will lead us to an error estimate such that the estimates will be within the error of the actual function values. |
|||||||||||||||||||||||||
5 |
The nth derivative of sin(x) is either a positive or negative multiple of the sine or cosine. The largest value attained by these functions is 1. So no matter what the value of c, 1 is the largest value this (derivative) term could be. |
|||||||||||||||||||||||||
6 |
|
In addition, because we only need approximate values on the interval [0, π/2], the largest value that (x – a) could be is π/2, because a = 0. |
||||||||||||||||||||||||
7 |
Thus, the largest the remainder could be is , so we need to find an n value that will make this less than our desired error of 0.000001. |
|||||||||||||||||||||||||
8 |
Find n such that . |
To solve the problem, we must find the error estimate for each value until we find an n value where the error is less than the specified error (0.000001). |
||||||||||||||||||||||||
9 |
Do loop |
This is, of course, a tedious calculation to do by hand; but if you are a programmer, you may realize that this is just a for or while loop with the condition to stop once the error limit is reached, as seen in the pseudocode at left. |
||||||||||||||||||||||||
10 |
We can also do this calculation using a programmable calculator or a spreadsheet like Excel. |
|||||||||||||||||||||||||
11 |
Let's use Excel to generate a table of error values. Recall that you can apply a formula to a cell, and then apply it to several cells by dragging the lower-right corner of the cell. |
|||||||||||||||||||||||||
12 |
Here, 1.570796327 was used to approximate π/2. |
|||||||||||||||||||||||||
13 |
|
Our table shows that for n + 1 = 12, the error is Thus, taking n = 11 will generate an approximation within our error bound. |
||||||||||||||||||||||||
14 |
p11(x) = |
Calculating the p11(x) Taylor polynomial for the sin (x) about x = 0 gives the result shown at left. |
||||||||||||||||||||||||
15 |
A graph of p11(x) with sin(x) shows them to be almost indistinguishable well beyond π), but our calculations have shown that we can use this approximation to calculate any value of sin(x) to within an error of less than a millionth. |