Let's redefine our function back to the cosine:
![[Graphics:../Images/index_gr_126.gif]](../Images/index_gr_126.gif)
![[Graphics:../Images/index_gr_127.gif]](../Images/index_gr_127.gif)
Notice that we specify the xDomain over which we want to use the Taylor series, but not the degree of the Taylor series (we are trying to find that).
We will make use of the errorFunction and errorBoundFunction defined above.
So, what degree Taylor series do we need to take to achieve a given level of accuracy over an interval? If we want an accuracy of at least
over our entire domain, for example, we would need to ensure that the maximum error is less than
at both endpoints (why there?). So, we can take our errorBoundFunction and substitute in the
value at the endpoint that maximizes
. We then have an equation in
that we can set equal to
and solve. Unfortunately, Mathematica can't solve this equation directly, so we either have to use Newton's method to solve (use FindRoot, though it may take some fooling around to find an initial guess that works) or just display a table of values and solve by inspection.
First, let's choose the x value such that
is a maximum size (why?):
![[Graphics:../Images/index_gr_135.gif]](../Images/index_gr_135.gif)
Set it equal to
and solve for n:
![[Graphics:../Images/index_gr_138.gif]](../Images/index_gr_138.gif)
WARNING: To trust FindRoot for a calculation like this, you will probably have to increase the WorkingPrecision to be significantly more decimals than your desired error (30 digits in this case) and you may also need to set MaxIterations to a larger number than the default of 15 (if you get an error message saying "Newton's method failed to converge to the prescribed accuracy after 15
iterations."). This isn't a big deal, but it is an extra thing to worry about. You could just list the errors for different values of
and find your answer by inspection:
![[Graphics:../Images/index_gr_141.gif]](../Images/index_gr_141.gif)
| n | Maximum error bound |
| 1 | 19.739208802178716` |
| 2 | 41.341702240399755` |
| 3 | 64.93939402266827` |
| 4 | 81.60524927607504` |
| 5 | 85.45681720669371` |
| 6 | 76.70585975306136` |
| 7 | 60.24464137187664` |
| 8 | 42.05869394489764` |
| 9 | 26.426256783374384` |
| 10 | 15.094642576822984` |
| 11 | 7.903536371318465` |
| 12 | 3.81995258484828` |
| 13 | 1.7143907110886711` |
| 14 | 0.7181223017785001` |
| 15 | 0.282005968455791` |
| 16 | 0.10422916220813977` |
| 17 | 0.03638284114254564` |
| 18 | 0.012031585942120619` |
| 19 | 0.0037798342006800365` |
| 20 | 0.0011309237482517954` |
| 21 | 0.00032299106720709754` |
| 22 | 0.00008823533599242998` |
| 23 | 0.000023099956945070423` |
| 24 | 5.8056524029499`*^-6 |
| 25 | 1.4029996106464105`*^-6 |
| 26 | 3.2649283479971135`*^-7 |
| 27 | 7.326482080403422`*^-8 |
| 28 | 1.587367053824321`*^-8 |
| 29 | 3.3245737832299737`*^-9 |
| 30 | 6.738359079814523`*^-10 |
| 31 | 1.3230737113997115`*^-10 |
| 32 | 2.5191264556915857`*^-11 |
| 33 | 4.655334803920223`*^-12 |
| 34 | 8.357237497140944`*^-13 |
| 35 | 1.4586131069623965`*^-13 |
| 36 | 2.4769557952772152`*^-14 |
| 37 | 4.095571647215559`*^-15 |
| 38 | 6.598265538022077`*^-16 |
| 39 | 1.0364531270342429`*^-16 |
| 40 | 1.5883480632589983`*^-17 |
So, taking
degree should do the trick. Recall that this is the worst your error should be on the interval. The actual error may be significantly smaller. It is interesting to look at how the error varies with the degree of the Taylor series:
![[Graphics:../Images/index_gr_143.gif]](../Images/index_gr_143.gif)
![[Graphics:../Images/index_gr_144.gif]](../Images/index_gr_144.gif)
Notice an interesting fact: The error actually gets worse as you increase the degree between 1 and 5, then improves steadily.