0

If we want to expand $f(x)=\sin x$ with Taylor polynomial centered at $x=0$. and error of that for$x=\frac{\pi}{2}$ be at most $10^{-6}$. then what order of polynomial should be at? ($n=?$)

As a hint our lecturer said we should use $c=\frac{\pi}{2}$ at formula of remainder of Taylor series.

Here is my work:

The reminder of Taylor series for the function $f(x)$ where $x_0=0$ is :

$$R_n(x)=\cfrac{f^{(n+1)}(c)}{(n+1)!}x^{n+1}$$

And I estimate $\frac{\pi}{2}$ to closest integer which is $2$ for the value of $x$.

To find $n$ I should solve inequality:

$$|R_n(x)|\le 10^{-6}\quad\rightarrow\quad|\cfrac{f^{(n+1)}(\frac{\pi}{2})}{(n+1)!}\times2^{n+1}|\le 10^{-6}$$

$(n+1)$'st derivative of $f(x)=\sin x$ can be one of the $\pm\sin x$ ,$\pm\cos x$. So $|f^{(n+1)}(\frac{\pi}{2})|\in\{0,1\}$. If it is equal to zero then we have $0\le 10^{-6}$ and it is absolutely wrong so the best I can do is using $|f^{(n+1)}(\frac{\pi}{2})|=1$. hence the inequality is $\left|\cfrac{2^{n+1}}{(n+1)!}\right|\le 10^{-6}$ . After plugging in some $n$s I got $n\ge13$. so the order of the Taylor polynomial should be $13$.

Is my approach right ? as you can see in my answer I had some difficulties to find $|f^{(n+1)}(\frac{\pi}{2})|$ did I right at this point?

Bernard
  • 175,478
Aligator
  • 1,454

2 Answers2

1

As $c$ can be anywhere in $[0,\frac\pi2]$, the best you can say is

$$\left|f^{(n+1)}(c)\right|\le1.$$

Now we can use the exact value of $\frac\pi2$ (unless a calculator is forbidden), and the possible remainders are bounded by the inverses of

$$8.11E-01, 3.94E+00, 4.79E+01, 1.09E+03, 3.97E+04, 2.12E+06 $$

and the order $11$ suffices.

Notice that as this is an alternating series, you need not precompute the number of terms, and you can stop when the current term becomes smaller than the requested error.

1

Write $$\sum_{n=0}^\infty\frac{(-1)^n }{(2 n+1)!}x^{2 n+1}=\sum_{n=0}^p\frac{(-1)^n }{(2 n+1)!}x^{2 n+1}+\sum_{n=p+1}^\infty\frac{(-1)^n }{(2 n+1)!}x^{2 n+1}$$ SInce it is an alternating series, you want to know $p$ such that $$R_p=\frac{x^{2 p+3}}{(2 p+3)!}\leq \epsilon\implies (2 p+3)! \geq\frac{x^{2 p+3}}{\epsilon}$$ If you have a look at this question of mine, you will see a magnificent approximation proposed by @robjohn.

Adapted to the present problem, this would give $$p\sim\frac{e \pi }{4}\,\exp\Big[W\left(-\frac{2 \log (\pi \epsilon )}{e \pi }\right)\Big]-\frac 74$$ where $W(.)$ is Lambert function. For sure, you need to use $\lceil p \rceil$.

For $\epsilon=10^{-6}$, this gives $p=4.31643$ and then $\lceil p \rceil=5$ (the exact solution would be $4.31727$). So, the expansion up to $n=11$ is sufficient, as @Yves Daoust already wrote (this would give $0.9999999437$ while one more term would lead to $1.000000001$).

Checking $$R_4=\frac{\pi ^{11}}{81749606400}\sim 3.60\times 10^{-6} > 10^{-6} $$ $$R_5=\frac{\pi ^{13}}{51011754393600}\sim 5.69\times 10^{-8} < 10^{-6} $$

If you cannot use Lambert function, since its argument is large, you could use the approximation given in the linked Wikipedia page $$W(x)= L_1-L_2+\frac{L_2}{L_1}+\frac{L_2(L_2-2)}{2L_1^2}+\frac{L_2(2L_2^2-9L_2+6)}{6L_1^3}+\cdots$$ where $L_1=\log(x)$ and $L_2=\log(L_1)$. For your value, this would would give $W(.)\sim 1.07011$ while its exact value is $1.04434$.

  • Hi Claude. Solid theoretical insight ! Anyway, from a practical standpoint, this takes much more computational effort than the computation of the sine itself :) (IMO, nothing beats straight computation until the terms are below tolerance, without doing any prediction !) –  Nov 12 '20 at 09:21
  • @YvesDaoust. For this problem, I fully agree with you. However, from a coding point of view, knowing in advance the number of terms to be added is really a plus since removing the IF test in the loop (this is an expensive operation). Just kidding; suppose $\epsilon=10^{-150}$, then $p=52$. Would you do it ? Cheers and don't forget to take care in this terrible time. – Claude Leibovici Nov 12 '20 at 13:53
  • I use to code some iterative algorithms with a fixed number of iterations, precisely to avoid testing a termination criterion (in contexts where accuracy is not critical) ! Cheers. –  Nov 12 '20 at 13:55