MHB Finding Taylor Polynomial for tan(x) - Wondering

  • Thread starter Thread starter mathmari
  • Start date Start date
  • Tags Tags
    Polynomial Taylor
mathmari
Gold Member
MHB
Messages
4,984
Reaction score
7
Hey! :o

Let $f :\rightarrow \mathbb{R}$, $f(x) := tan(x)$.

I want to find a $N\in \mathbb{N}$ such that for the $N$-th Taylor polynomial $P_N$ at $0$, that is defined as follows
$P_N(x)=\sum_{n=0}^N\frac{f^{(n)}(0)}{n!}x^n$, it holds that
$$\left |f(x)-P_N(x)\right |\leq 10^{-5}, \ \ x\in \left [-\frac{1}{10}, \frac{1}{10}\right ]$$ For that do we have to write $f$ as a power series? But which is the formula? (Wondering)

Or do we have to do something else? (Wondering)
 
Physics news on Phys.org
mathmari said:
Hey! :o

Let $f :\rightarrow \mathbb{R}$, $f(x) := tan(x)$.

I want to find a $N\in \mathbb{N}$ such that for the $N$-th Taylor polynomial $P_N$ at $0$, that is defined as follows
$P_N(x)=\sum_{n=0}^N\frac{f^{(n)}(0)}{n!}x^n$, it holds that
$$\left |f(x)-P_N(x)\right |\leq 10^{-5}, \ \ x\in \left [-\frac{1}{10}, \frac{1}{10}\right ]$$ For that do we have to write $f$ as a power series? But which is the formula? (Wondering)

Or do we have to do something else? (Wondering)

Yes write the power series.
 
Prove It said:
Yes write the power series.

We have that the power series of $\sin (x)$ is $$\sin (x)=\sum_{n=0}^{\infty}(-1)^n\frac{x^{2n+1}}{(2n+1)!}$$ and the power series of $\cos (x)$ is $$\cos (x)=\sum_{n=0}^{\infty}(-1)^n\frac{x^{2n}}{(2n)!}$$

Since $\tan (x)=\frac{\sin (x)}{\cos (x)}$, we get that $$\tan (x)=\frac{\displaystyle{\sum_{n=0}^{\infty}(-1)^n\frac{x^{2n+1}}{(2n+1)!}}}{\displaystyle{\sum_{n=0}^{\infty}(-1)^n\frac{x^{2n}}{(2n)!}}}$$

To what is that equal? (Wondering)
 
How about using the known expansion for $\tan$? (Wondering)

See e.g. here.
 
I like Serena said:
How about using the know expansion for $\tan$? (Wondering)

See e.g. here.

So, we have that $$\tan (x)=\sum_{n=0}^{\infty}\frac{(-1)^n2^{2n+2}(2^{2n+2}-1)B_{2n+2}}{(2n+2)!}x^{2n+1}$$ where $B_n$ is a Bernoulli number.

$P_N$ is the power series of $\tan (x)$ that is stopped at $N$, or not? (Wondering)

Then we have that $$\left |f(x)-P_N(x)\right |=\left |\sum_{n=0}^{\infty}\frac{(-1)^n2^{2n+2}(2^{2n+2}-1)B_{2n+2}}{(2n+2)!}x^{2n+1}-\sum_{n=0}^N\frac{f^{(n)}(0)}{n!}x^n\right |=\left |\sum_{n=N+1}^{\infty}\frac{(-1)^n2^{2n+2}(2^{2n+2}-1)B_{2n+2}}{(2n+2)!}x^{2n+1}\right |\leq \sum_{n=N+1}^{\infty}\frac{2^{2n+2}(2^{2n+2}-1)B_{2n+2}}{(2n+2)!}\left (\frac{1}{10}\right )^{2n+1}$$

It holds that $$\frac{x}{e^x-1}=\sum_{n=0}^{\infty}\frac{B_nx^n}{n!}$$ Could we apply this in this case? But how? Now we have that the starts from $N+1$. (Wondering)
 
A Taylor series around 0 (aka MacLaurin series) up to degree $N$ has a remainder of:
$$R_N(x) = \frac{f^{(N+1)}(\theta x)}{(N+1)!}x^{N+1}$$
where $0 \le \theta \le 1$.

This is called the Lagrange form of the remainder. See e.g. here.

So:
$$|R_N(x)| \le \frac{\max_{0\le\theta\le 1} |f^{(N+1)}(\theta x)|}{(N+1)!}|x|^{N+1}$$

And perhaps we can pick the tangent expansion:
$$\tan x = x + \frac 13 x^3 + \frac 2{15} x^5 + \frac {17}{315} x^7 + \frac{62}{2835} x^9 + ...$$
(Thinking)
 
I like Serena said:
A Taylor series around 0 (aka MacLaurin series) up to degree $N$ has a remainder of:
$$R_N(x) = \frac{f^{(N+1)}(\theta x)}{(N+1)!}x^{N+1}$$
where $0 \le \theta \le 1$.

This is called the Lagrange form of the remainder. See e.g. here.

So:
$$|R_N(x)| \le \frac{\max_{0\le\theta\le 1} |f^{(N+1)}(\theta x)|}{(N+1)!}|x|^{N+1}$$

And perhaps we can pick the tangent expansion:
$$\tan x = x + \frac 13 x^3 + \frac 2{15} x^5 + \frac {17}{315} x^7 + \frac{62}{2835} x^9 + ...$$
(Thinking)

So, we have that $f-P_N$ is the remainder, right? (Wondering)

$$|R_N(x)| \le \frac{\max_{0\le\theta\le 1} |f^{(N+1)}(\theta x)|}{(N+1)!}|x|^{N+1}\leq \frac{\max_{0\le\theta\le 1} |f^{(N+1)}(\theta x)|}{(N+1)!}\left |\frac{1}{10}\right |^{N+1}$$

Do we use the tangent expansion to find the $\max_{0\le\theta\le 1} |f^{(N+1)}(\theta x)|$ ? (Wondering)
 
mathmari said:
So, we have that $f-P_N$ is the remainder, right? (Wondering)

$$|R_N(x)| \le \frac{\max_{0\le\theta\le 1} |f^{(N+1)}(\theta x)|}{(N+1)!}|x|^{N+1}\leq \frac{\max_{0\le\theta\le 1} |f^{(N+1)}(\theta x)|}{(N+1)!}\left |\frac{1}{10}\right |^{N+1}$$

Do we use the tangent expansion to find the $\max_{0\le\theta\le 1} |f^{(N+1)}(\theta x)|$ ? (Wondering)

Yes.

Formally, we indeed need to find the higher order derivatives of $\tan$ to find that upper bound.
However, we usually make the assumption that the remainder is less than the last term of the series.
So for $N=3$ we would assume that:
$$|R_3(x)| = |f(x) - P_3(x)| \le \frac 13 |x|^3 \le \frac 13 \left(\frac 1{10}\right)^3 < 4 \cdot 10^{-4}$$
(Thinking)
 
I like Serena said:
Yes.

Formally, we indeed need to find the higher order derivatives of $\tan$ to find that upper bound.
However, we usually make the assumption that the remainder is less than the last term of the series.
So for $N=3$ we would assume that:
$$|R_3(x)| = |f(x) - P_3(x)| \le \frac 13 |x|^3 \le \frac 13 \left(\frac 1{10}\right)^3 < 4 \cdot 10^{-4}$$
(Thinking)

And which value do we take in this case where we don't know the value of N? (Wondering)
 
  • #10
mathmari said:
And which value do we take in this case where we don't know the value of N? (Wondering)

We should try them.

Note that if we ask Wolfram|Alpha, we find that:
$$\max_{-1/10 \le x\le 1/10} \tan^{(4)} x < 2$$
so that:
$$|R_3(x)| < \frac {2}{4!} \left| \frac 1{10}\right|^4 < 10^{-5}$$
(Thinking)

Or alternatively we assume that:
$$|R_5(x)| \le \frac{2}{15} \left|\frac 1{10}\right|^5 < 10^{-5}$$
 
  • #11
Do we have to take all the N's till we get a result $>10^{-5}$ ? (Wondering)
 
  • #12
mathmari said:
Do we have to take all the N's till we get a result $>10^{-5}$ ? (Wondering)

Not really. The problem statement does not require us to find the lowest $N$.

So we can pick any $N$ that seems to be sufficiently high and check the remainder.
Actually, we can already predict that to get $R_N(x) < 10^{-5}$ it will suffice to pick $N=5$, since the 5th term has a fraction that is less than $1$. (Nerd)
 
  • #13
Alternatively, we can analyze:
$$R_3(x) = \tan x - (x+\frac 13 x^3)$$
It's anti-symmetric and if we take the derivative we can see that it's an increasing function.
So it's maximum absolute value is at $x=\frac 1{10}$.
W|A tells us that:
$$R_3(\frac 1{10}) \approx 1.3 \cdot 10^{-6}$$
 
  • #14
I like Serena said:
So we can pick any $N$ that seems to be sufficiently high and check the remainder.
Actually, we can already predict that to get $R_N(x) < 10^{-5}$ it will suffice to pick $N=5$, since the 5th term has a fraction that is less than $1$. (Nerd)

For $N=5$ do we take the part of the tangent expansion of degree $5$ and that will we bigger that the $R_5$ ? (Wondering)
 
  • #15
An alternative (and probably easier) method is to remember that in an alternating series, the error in truncating to n terms is never any more than the absolute value of the "n+1"th term.
 
  • #16
mathmari said:
For $N=5$ do we take the part of the tangent expansion of degree $5$ and that will we bigger that the $R_5$ ? (Wondering)

Yes. That's true by assumption, which is generally true for 'nice' series like tan.

Prove It said:
An alternative (and probably easier) method is to remember that in an alternating series, the error in truncating to n terms is never any more than the absolute value of the "n+1"th term.

That's not true for just any alternating series, is it? There's an additional condition.
And anyway, the series at hand is not alternating.
 
  • #17
I like Serena said:
That's not true for just any alternating series, is it? There's an additional condition.
And anyway, the series at hand is not alternating.

As a matter of fact, it IS true for EVERY alternating series.

But I was mistaken about the series itself, it is not alternating, I forgot that the Bernoulli numbers do not have a pattern to the positives and negatives.
 
  • #18
Prove It said:
As a matter of fact, it IS true for EVERY alternating series.

Counter example: 1 - 2 + 10000 - 1/2 + 1/3 - 1/4 + ...

In particular the remainder is bigger than term 1 or term 2.
I believe we need the additional condition that the terms are absolutely decreasing (which is a sufficient condition to ensure the series converges as well).
It also means we need to prove that for any Taylor expansion we want to apply it to.
 
  • #19
I like Serena said:
Not really. The problem statement does not require us to find the lowest $N$.

We cannot find an interval of $N$ such that the inequality holds, can we? (Wondering)
 
  • #20
mathmari said:
We cannot find an interval of $N$ such that the inequality holds, can we? (Wondering)

To find the lowest value of N for which the inequality holds we need to evaluate $\tan(1/10) - P_N(1/10)$ for $N=0,1,...$ until we find it. (Thinking)
 
  • #21
I like Serena said:
To find the lowest value of N for which the inequality holds we need to evaluate $\tan(1/10) - P_N(1/10)$ for $N=0,1,...$ until we find it. (Thinking)

Ah ok. (Thinking)
I like Serena said:
we can analyze:
$$R_3(x) = \tan x - (x+\frac 13 x^3)$$
It's anti-symmetric and if we take the derivative we can see that it's an increasing function.

The derivative is $\frac{1}{\cos^2(x)}-1-x^2$. Is this always positive? (Wondering)
 
  • #22
One root of $\frac{1}{\cos^2(x)}-1-x^2$ is $x=0$.

This function is symmetric, right? (Wondering)

But can we find it the function is positive or negative? (Wondering)
 
  • #23
mathmari said:
One root of $\frac{1}{\cos^2(x)}-1-x^2$ is $x=0$.

This function is symmetric, right? (Wondering)

But can we find it the function is positive or negative? (Wondering)

The function is non-negative for $\frac \pi 2<x<\frac \pi 2$, as we can see here:
\begin{tikzpicture}[scale=2]
\draw[<->] (-1.2,0) -- (1.2,0);
\draw[->] (0,0) -- (0,1.7);
\foreach \i in {-1,-.5,...,1} {\draw (\i,.05) -- (\i,-.05) node[below] {$\i$}; }
\foreach \i in {.5,1,...,1.5} { \draw (.05,\i) -- (-.05,\i) node
{$\i$}; }
\draw[blue, ultra thick, domain=-1:1, variable=\x] plot ({\x}, {(sec(deg(\x))^2) - 1 - (\x)^2});
\end{tikzpicture}

However, it's a bit painful to formally prove it.
We can make a Taylor expansion, which is:
$$\frac{1}{\cos^2(x)}-1-x^2 = \frac 23 x^4 + \frac{17}{45} x^6 + ...$$
It confirms that it's indeed non-negative, although formally this is not a proof. (Doh)​
 
  • #24
Ah ok. (Thinking)

Is it maybe better to use the formula for the remainder term $R_N(x)=\frac{f^{(N+1)}(\xi )}{(N+1)!}x^{N+1}$ ? (Wondering) We have that $f^{(4)}=8\frac{ 2\sin (x)+\sin^3 (x)}{\cos^5(x)}$.

So, we have that $$R_3(x)=\frac{f^{(4)}(\xi )}{(4)!}x^{4}=\frac{8\frac{ 2\sin (\xi)+\sin^3 (\xi)}{\cos^5(\xi)}}{1\cdot 2\cdot 3\cdot 4}x^4=\frac{1}{3}\frac{ 2\sin (\xi)+\sin^3 (\xi)}{\cos^5(\xi)}x^4$$

Therefore $$|f(x)-P_N(x)|=|R_3|=\left |\frac{1}{3}\frac{ 2\sin (\xi)+\sin^3 (\xi)}{\cos^5(\xi)}x^4\right |=\frac{1}{3}\left |\frac{ 2\sin (\xi)+\sin^3 (\xi)}{\cos^5(\xi)}x^4\right |\leq \frac{1}{3}\left |\frac{ 2\sin (\xi)+\sin^3 (\xi)}{\cos^5(\xi)}\right |\cdot \left |x^4\right | \\ \leq \frac{1}{3}\left |\frac{ 2\sin (\xi)+\sin^3 (\xi)}{\cos^5(\xi)}\right |\cdot \left (\frac{1}{10}\right )^4$$

But how could we bound the absolute value $\left |\frac{ 2\sin (\xi)+\sin^3 (\xi)}{\cos^5(\xi)}\right |$ ? (Wondering)
 
Last edited by a moderator:
  • #25
I like Serena said:
Counter example: 1 - 2 + 10000 - 1/2 + 1/3 - 1/4 + ...

In particular the remainder is bigger than term 1 or term 2.
I believe we need the additional condition that the terms are absolutely decreasing (which is a sufficient condition to ensure the series converges as well).
It also means we need to prove that for any Taylor expansion we want to apply it to.

I did mean every convergent alternating series (I thought that was implied)...
 
  • #26
mathmari said:
But how could we bound the absolute value $\left |\frac{ 2\sin (\xi)+\sin^3 (\xi)}{\cos^5(\xi)}\right |$ ? (Wondering)

For $0<\xi\le\frac 1{10}$ the function $f^{(4)}$ is positive since both $\sin$ and $\cos$ are positive then.
The numerator is largest when $\xi$ is largest, since $\sin$ is an increasing function.
And the denominator is smallest when $\xi$ is largest as well, since $\cos$ is a decreasing function.
So the function has the largest value when $\xi=\frac 1{10}$.

Since the function is anti-symmetric, the function has the same largest value for $\xi=-\frac 1{10}$, just negative.
(Thinking)

Prove It said:
I did mean every convergent alternating series (I thought that was implied)...

Erm... the counter example I gave is a convergent alternating series.
 
  • #27
I like Serena said:
For $0<\xi\le\frac 1{10}$ the function $f^{(4)}$ is positive since both $\sin$ and $\cos$ are positive then.
The numerator is largest when $\xi$ is largest, since $\sin$ is an increasing function.
And the denominator is smallest when $\xi$ is largest as well, since $\cos$ is a decreasing function.
So the function has the largest value when $\xi=\frac 1{10}$.

Since the function is anti-symmetric, the function has the same largest value for $\xi=-\frac 1{10}$, just negative.
(Thinking)

So, we have that \begin{equation*}\left |\frac{ 2\sin (\xi)+\sin^3 (\xi)}{\cos^5(\xi)}\right |\leq \left |\frac{ 2\sin \left (\frac{1}{10}\right )+\sin^3 \left (\frac{1}{10}\right )}{\cos^5\left (\frac{1}{10}\right )}\right |\end{equation*} right? (Wondering)

Do we have to use here a calculator, or could we do here something without it? (Wondering)

It holds that $|\sin (x)|\leq x$, right? Do we have a similar inequality for $\frac{1}{\cos (x)}$ ? (Wondering)
 
  • #28
How about $\frac{1}{\cos (x)} \le 1 + |x|$? (Wondering)
 
  • #29
I like Serena said:
How about $\frac{1}{\cos (x)} \le 1 + |x|$? (Wondering)

We get this inequality from the Taylor expansion of $\cos (x)$, right? (Wondering) So, we have that \begin{equation*}\left |\frac{ 2\sin (\xi)+\sin^3 (\xi)}{\cos^5(\xi)}\right |\leq \left |\frac{ 2\sin \left (\frac{1}{10}\right )+\sin^3 \left (\frac{1}{10}\right )}{\cos^5\left (\frac{1}{10}\right )}\right |= \left |2\sin \left (\frac{1}{10}\right )+\sin^3 \left (\frac{1}{10}\right )\right |\cdot \left |\frac{1}{\cos^5\left (\frac{1}{10}\right )}\right |\leq \left (2 \frac{1}{10}+\frac{1}{10^3}\right )\cdot \left (1+\frac{1}{10}\right )^5\end{equation*}

The last value is not smaller than $10^{-5}$ ( Wolfram ) (Wondering)

So, we have to do something else...

We have that $$|\cos (x)|=\left |\sum_{n=0}^{\infty}(-1)^n\frac{x^{2n}}{(2n)!} \right |=\sum_{n=0}^{\infty}\frac{x^{2n}}{(2n)!}\geq 1$$

Therefore $\frac{1}{|\cos(x)|}\leq 1$.

Is this correct? (Wondering)
 
Last edited by a moderator:
  • #30
mathmari said:
We get this inequality from the Taylor expansion of $\cos (x)$, right? (Wondering)

No, the Taylor expansion is $\cos x = 1-\frac 12 x^2 + \frac 1{4!}x^4 - ...$.
It's just that $\cos$ has a horizontal tangent at $x=0$.
We can set a bound with a line that has a non-horizontal tangent.
We can see it in this picture:
\begin{tikzpicture}[scale=2]
\draw[<->] (-1.2,0) -- (1.2,0);
\draw[->] (0,0) -- (0,2.2);
\foreach \i in {-1,-0.5,...,1} {\draw (\i,.05) -- (\i,-.05) node[below] {$\i$}; }
\foreach \i in {0.5,1,...,2} { \draw (.05,\i) -- (-.05,\i) node
{$\i$}; }
\draw[domain=-1:1, variable=\x, red, ultra thick] plot ({\x}, {(cos(deg(\x)))}) node
{$\cos x$};
\draw[domain=-1:1, variable=\x, red, ultra thick] plot ({\x}, {1-abs(\x)}) node[above right] {$1-|x|$};
\draw[domain=-1:1, variable=\x, blue, ultra thick] plot ({\x}, {(sec(deg(\x)))}) node
{$\frac{1}{\cos x}$};
\draw[domain=-1:1, variable=\x, blue, ultra thick] plot ({\x}, {1+abs(\x)}) node
{$1+|x|$};
\end{tikzpicture}

For the record, based on the $\cos$ expansion, we can write $\cos(x) \ge 1-\frac 12 x^2$.

So, we have that \begin{equation*}\left |\frac{ 2\sin (\xi)+\sin^3 (\xi)}{\cos^5(\xi)}\right |\leq \left |\frac{ 2\sin \left (\frac{1}{10}\right )+\sin^3 \left (\frac{1}{10}\right )}{\cos^5\left (\frac{1}{10}\right )}\right |= \left |2\sin \left (\frac{1}{10}\right )+\sin^3 \left (\frac{1}{10}\right )\right |\cdot \left |\frac{1}{\cos^5\left (\frac{1}{10}\right )}\right |\leq \left (2 \frac{1}{10}+\frac{1}{10^3}\right )\cdot \left (1+\frac{1}{10}\right )^5\end{equation*}

The last value is not smaller than $10^{-5}$ ( Wolfram ) (Wondering)

So, we have to do something else...

The remainder term is actually:
$$R_3(x) = \frac{1}{4!} f^{(4)}\,(\xi) x^4$$
I think we need a couple more factors... (Thinking)
We have that $$|\cos (x)|=\left |\sum_{n=0}^{\infty}(-1)^n\frac{x^{2n}}{(2n)!} \right |=\sum_{n=0}^{\infty}\frac{x^{2n}}{(2n)!}\geq 1$$

Therefore $\frac{1}{|\cos(x)|}\leq 1$.

Is this correct? (Wondering)

Not quite. $|\cos x|\le 1$. Therefore $\frac{1}{|\cos(x)|}\ge 1$. (Nerd)​
 
  • #31
I like Serena said:
No, the Taylor expansion is $\cos x = 1-\frac 12 x^2 + \frac 1{4!}x^4 - ...$.
It's just that $\cos$ has a horizontal tangent at $x=0$.
We can set a bound with a line that has a non-horizontal tangent.$|\cos x|\le 1$. Therefore $\frac{1}{|\cos(x)|}\ge 1$. (Nerd)
Ah ok... (Thinking)
I like Serena said:
The remainder term is actually:
$$R_3(x) = \frac{1}{4!} f^{(4)}\,(\xi) x^4$$
I think we need a couple more factors... (Thinking)
What do you mean? (Wondering)
 
  • #32
mathmari said:
What do you mean? (Wondering)

We've evaluated an upper bound for $f^{(4)}(\xi)$, which is approximately $2.6$.
Btw, I think there's a factor $8$ missing in the expression. (Worried)

But we need an upper bound for $R_3(x) = \frac 1{4!}f^{(4)}(\xi)\left(\frac 1{10}\right)^4 = \frac{1}{24}\cdot 10^{-4}f^{(4)}(\xi) < 4\cdot 10^{-6}\cdot f^{(4)}(\xi)$. (Thinking)
 
  • #33
I like Serena said:
We've evaluated an upper bound for $f^{(4)}(\xi)$, which is approximately $2.6$.
Btw, I think there's a factor $8$ missing in the expression. (Worried)

But we need an upper bound for $R_3(x) = \frac 1{4!}f^{(4)}(\xi)\left(\frac 1{10}\right)^4 = \frac{1}{24}\cdot 10^{-4}f^{(4)}(\xi) < 4\cdot 10^{-6}\cdot f^{(4)}(\xi)$. (Thinking)

I see! Thanks a lot! (Mmm)
 

Similar threads

Back
Top