<s>[INST] $n^{th}$ derivative of $y=x^2\cos x$ I am stuck with Leibniz formula
$$D^{n}y = \sum_{k=0}^{n} \binom{n}{k} \, x^{(2k)}\cos^{(n-k)}x$$
Could someone show how to do it?
 [/INST] I would use the fact that:
$$\cos^{(n)}(x)=\cos\Bigl(x+\frac{n\pi}2\Bigr)$$
and that $$(x^2)'=2x,\quad (x^2)''=2,\quad (x^2)^{(n)}=0\enspace\text{si}\enspace n>2.$$
Thus Leibniz's rule gives:
$$\bigl(x^2\cos x\bigr)^{(n)} =x^2\cos^{(n)}(x)+2nx\cos^{(n-1)}(x)+n(n-1)\cos^{(n-2)}(x)$$
Also, note that $\;\cos^{(n-2)}(x)=-\cos^{(n)}(x)$, hence
\begin{align*}\bigl(x^2\cos x\bigr)^{(n)}&=\bigl(x^2-n(n-1)\bigr)\cos^{(n)}(x)+2nx\cos^{(n-1)}(x)\\
&=\bigl(x^2-n(n-1)\bigr)\cos\Bigl(x+\frac{n\pi}2\Bigr)+2nx\cos\Bigl(x+\frac{(n-1)\pi}2\Bigr)
\end{align*}
There remains to consider the different cases according to the values of $n$ modulo $4$:
$$\text{if }\begin{cases}
n\equiv 0&\bigl(x^2\cos x\bigr)^{(n)} =\bigl(x^2-n(n-1)\bigr)\cos x+2nx\sin x\\
n\equiv 1&\bigl(x^2\cos x\bigr)^{(n)} =2nx\cos x-\bigl(x^2-n(n-1)\bigr)\sin x\\
n\equiv 2&\bigl(x^2\cos x\bigr)^{(n)} =\bigl(n(n-1)-x^2\bigr)\cos x-2nx\sin x\\
n\equiv 3&\bigl(x^2\cos x\bigr)^{(n)} = -2nx\cos x+\bigl(x^2-n(n-1)\bigr)\sin x\\
\end{cases}$$
</s>