# The differentiation of $\sin, \cos$ through a Taylor Series

This question has been asked quite a lot on math SE, however, please before you mark this as a duplicate carry on reading, I will try to highlight my doubts and concerns as clear as possible.

First in class we had the following theorem:

Let $(a_n)_{n \in \mathbb{N}}$ be a sequence in $\mathbb{R}$. Let $R > 0$ such that $f(x)=\sum_{n=0}^{+ \infty} a_nx^n$ converges absolutely for $|x|< R$, then $f(x)$ is differentiable and $\forall x \in ]-R,R[$ the derivative is $f'(x)=\sum_{n=1}^{+ \infty} na_nx^{n-1}$

I do understand the meaning of this theorem, however, when it comes to applying it I seem to end up at horrible wrong results. What puzzles me the most is (and I won't link the specific cases in here) that I have seen many answers on math SE and other online resources where people differentiate the sum without raising the initial value from $n=0$ to $n=1$ and neither shift the index, however they always seem to succeed to show what they want with this approach.

Example (No Problem here, works perfect):

Without thinking much about it and just using and intuitive understanding of the theorem given above I differentiate the following: $$\cos'(x)= \left(\sum_{n=0}^{+ \infty} \frac{(-1)^n x^{2n}}{(2n)!} \right)'=\sum_{n=1}^{+ \infty} \frac{(-1)^n2nx^{2n-1}}{(2n)!}=\sum_{n=1}^{+ \infty} \frac{(-1)^nx^{2n-1}}{(2n-1)!}$$ notice the index which I am about to shift now (using $i=n-1$ and replacing it in my mind) $$\implies \cos '(x)= \sum_{n=0}^{+ \infty} \frac{(-1)^{n+1}x^{2n+1}}{(2n+1)!}=-\sum_{n=0}^{+ \infty} \frac{(-1)^nx^{2n+1}}{(2n+1)!}=-\sin(x)$$ things work out perfectly here obviously but when it comes to the same exercise with $\sin$ however I seem to fail

Example 2 (Here I struggle) $$\sin'(x)= \left(\sum_{n=0}^{+ \infty} \frac{(-1)^n x^{2n+1}}{(2n+1)!} \right)'=\sum_{n=1}^{+ \infty} \frac{(-1)^n(2n+1)x^{2n}}{(2n+1)!}=\sum_{n=1}^{+ \infty} \frac{(-1)^nx^{2n}}{(2n)!}$$ Things look seemingly good so far, but I yet still have to shift the index, I did this above with luck so why not here? $$\implies \sin'(x)=\sum_{n=0}^{+ \infty} \frac{(-1)^{n+1}x^{2n+2}}{(2n+2)!}=-\sum_{n=0}^{+ \infty} \frac{(-1)^nx^{2n+2}}{(2n+2)!}\neq \cos(x)$$

Questions:

$\bullet$Where is my mistake in the second example? Was my approach in example one only a lucky goal? $\bullet$Why are there so many people not increasing the index when they differentiate a sum? Is this a correct approach and when yes, for which cases?

$\bullet$ What would be the correct, mathematical rigorous approach to solve this problems? Do I always have to define $a_n$ first? i.e. for the second example define $$a_n:=\frac{(-1)^nx^{n+1}}{(2n+1)!}$$ I have tried this method and my result was even worse then before.

-
Things are less confusing if you write $\cos(x)=\sum_{n\geq0}\epsilon_n\frac{x^n}{n!}$ where $\epsilon_n=0$ if $n$ odd and $\epsilon_n=(-1)^{n/2}$ for $n$ even. Then with the same notation $\sin(x)=\sum_{n\geq0}\epsilon_{n-1}\frac{x^n}{n!}$. –  Marc van Leeuwen Dec 2 '13 at 15:07

In the theorem you have $x^n$, but in the series you have $x^{2n}$ and $x^{2n+1}$. In the theorem you drop the $n=0$ term because that's the constant term (whose derivative is zero); in the case of cosine, the $n=0$ term is again the constant term, so it works out; but in the case of sine it's the $x^1$ term. To apply the theorem very carefully for cosine: let $$a_n = \begin{cases} (-1)^{n/2}/n! &\text{if n even,} \\ 0 &\text{if n odd.} \end{cases}$$ Then $$\cos'(x) = \left(\sum_{n=0}^\infty a_n x^n\right)' = \sum_{n=1}^\infty na_n x^{n-1} = \sum_{n=0}^\infty (n+1)a_{n+1} x^n$$ and then note that $$(n+1)a_{n+1} = \begin{cases} (-1)^{(n+1)/2}/n! &\text{if n odd,} \\ 0 &\text{if n even.} \end{cases}$$

-
Thanks a lot for your effort. It makes much more sense to me now the way you apply the theorem, I was trying to safe it by choosing the substitution as given in my post post above. In general it seems me however that the easiest approach is to write out the sum. –  Spaced Dec 2 '13 at 15:05
Another alternative is to write $(\sum_{n=0}^\infty a_n x^n)' = \sum_{n=0}^\infty (a_nx^n)'$ (which is the "real" meaning of the theorem), and then to drop zero terms from the sum as a separate step. This will still work when the indexing is different (as in your examples), as long as you're careful about figuring out which terms are zero. –  Steven Taschuk Dec 2 '13 at 15:18

You misunderstood why you go from $\sum\limits_{n=0}^\infty$ to $\sum\limits_{n=1}^\infty$. It's not that you're getting rid of the lowest power term, as you have done. But rather that you're getting rid of the $x^0$ term, which is constant. So when you differentiate $\sin(x)$, you don't get rid of the $n=0$ term, because that's the $x^1$ term.

-

This is wrong:

$$\sin'(x)= \left(\sum_{n=0}^{+ \infty} \frac{(-1)^n x^{2n+1}}{(2n+1)!} \right)'=\sum_{n=1}^{+ \infty} \frac{(-1)^n(2n+1)x^{2n}}{(2n+1)!}$$

The point of discarding the derivative of the first term $a_0x^0$ is simply that the derivative of a constant term is zero, so it can be left out. Otherwise the first term would be $0 \times a_0x^{-1}$, which is a nuisance because it's undefined at $x = 0$.

But your first term here is not a constant, because your exponent is $2n+1$ instead of $n$. If you just write out a few terms and differentiate them, all will become clear.

-
written out, as suggest below by @Tim.Ratigan I understand it perfectly, however I was hoping that this can be avoided, especially for more complex functions like the Bessel Function and so on. So in general you'd recommend to write out the sum and differentiate from there rather than to differentiate the given sum in it's summation expression? –  Spaced Dec 2 '13 at 14:59
No, I was just suggesting that you try it for this case to see why it doesn't work. Now that you understand why, you will know in future that you can only discard the first term if it is of the form $a_0x^0$. –  TonyK Dec 2 '13 at 15:16

When you take the derivative of sine, note that the Taylor expansion is $(0,1,0,-1,0,1,\ldots)$. By writing sine as $\sum_{n=0}^\infty \frac{(-1)^nx^{2n+1}}{(2n+1)!}$, you are not expressing it in its canonical Taylor form. By shifting the index in deriving sine, you are shifting $n$ by $2$. This might be easier to see if you write it out:

\begin{align}\sin x&=x-\frac{x^3}{3!}+\frac{x^5}{5!}-\frac{x^7}{7!}+\frac{x^9}{9!}\ldots\\ \frac{\text d(\sin x)}{\text dx}&=1-\frac{x^2}{2!}+\frac{x^4}{4!}-\frac{x^6}{6!}+\frac{x^8}{8!}\ldots\tag{1}\end{align}

But your sum neglects the $1$ in $(1)$.

In general, it's usually easier to write $f'(x)=\sum_{n=0}^\infty na_nx^{n-1}$ anyway, since the first term is $0$ and you don't run the risk of forgetting terms.

As TonyK kindly pointed out, take care to note that the above sum does not evaluate definitely at $x=0$ since it has a $0^{-1}$ term in it, hence this identity should be taken with a pinch of salt.

-
Thanks for your advice, I will try writing the sums out first before differentiating and then see if the pattern can be described in a simple form with the summation notation. –  Spaced Dec 2 '13 at 15:09
@Tim: The problem with retaining the first term $0 \times a_0x^{-1}$ is that, formally speaking, it's undefined at $x=0$. –  TonyK Dec 2 '13 at 15:17
@TonyK that's why I said usually. Sorry if that was too subtle. –  Tim Ratigan Dec 2 '13 at 15:33
@Tim: No, subtlety is what was missing from your answer. –  TonyK Dec 2 '13 at 16:22
I'd also like to point out that $\sum_{n=1}na_nx^{n-1}$ still has a $0^0$ term at $x=0$ that is also technically undefined but ignored anyway. I really don't think this is a serious issue, but I'll add it in if it will make you happy. –  Tim Ratigan Dec 2 '13 at 17:22