Here's the problem:

Taylor's theorem states that if [imath]T_n(x)[/imath] is the [imath]n[/imath]th degree Taylor polynomial of [imath]f(x) = cos(x)[/imath] centered at [imath]a = 0[/imath], then for all [imath]\beta[/imath] there exists an [imath]\alpha[/imath], [imath]0 < \alpha < \beta[/imath], such that [math]f(\beta) = T_n(\beta) + {f^{n+1}(\alpha)\over(n + 1)!}(\beta)^{n+1}[/math] How large must [imath]n[/imath] be so that the [imath]n[/imath]th degree Taylor polynomial of [imath]f(x) = cos(x)[/imath] centered at [imath]a = 0[/imath] approximates [imath]cos(x)[/imath] to within [imath]\epsilon = .0001[/imath] for all [imath]x \in [0,10][/imath]?

Here's how I solved it:

We need [imath]|f(10) - T_n(10)| \le .0001[/imath] or [imath]|{f^{n+1}(\alpha)\over(n + 1)!}(10)^{n+1}| \le .0001[/imath], so

[math]|f^{n+1}(\alpha)| \le 1 \iff {|f^{n+1}(\alpha)|\over(n + 1)!}(10)^{n+1} \le {(10)^{n+1}\over(n + 1)!}[/math]

[math]{(10)^{n+1}\over(n + 1)!} \le {1\over10000} \iff 10^{n+5} \le (n+1)! \iff n \ge 34[/math]

[math]\therefore n \ge 34 \Rightarrow |f(10) - T_n(10)| \le .0001[/math]

It turns out that that's the answer my professor was looking for, but before I knew that I wanted to check my answer, so I wrote a python script to evaluate the Taylor polynomial:

Code: Select all

`from math import factorial`

print('Cosine Taylor polynomial evaluator.')

degree=input('What degree?')

x=input('Evaluate at x=')

degree = degree/2

sum=0

for i in range(0,degree+1):

sum += (float(((-1)**i))/factorial(2*i)) * (x**(2*i))

print(sum)

According to my script, if [imath]n \ge 32[/imath] then [imath]|f(10) - T_n(10)| \le .0001[/imath]

Code: Select all

`What degree?31`

Evaluate at x=10

-0.83942020518

Cosine Taylor polynomial evaluator.

What degree?32

Evaluate at x=10

-0.839040166105

Cosine Taylor polynomial evaluator.

What degree?33

Evaluate at x=10

-0.839040166105

Cosine Taylor polynomial evaluator.

What degree?34

Evaluate at x=10

-0.83907403768

According to my calculator:

[imath]cos(10) = -0.839071529[/imath]

So here's my question: Where's the discrepancy come from? Is it that my script is dealing with crazy numbers like 1/32! and python isn't precise enough? Or is it because there's some wiggle room in the Taylor remainder when I used [imath]f^{n+1}(\alpha)\le1[/imath] ?