$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?
 A: Write $$f^{(n)}(x) = a_n(x)\cos x +b_n(x)\sin x$$
The proceed by induction to detrmine recurrences for polynomials $a_n(x), b_n(x)$.
Specifically, if:
$$f^{(n)}(x)=(A_nx^2+B_nx+C_n)\cos x + (D_nx^2+E_nx+F_n)\sin x$$
You get the recurrence:
$$\begin{pmatrix}A_{n+1}\\B_{n+1}\\C_{n+1}\\D_{n+1}\\E_{n+1}\\F_{n+1}\end{pmatrix} = \begin{pmatrix}0&0&0&1&0&0\\
2&0&0&0&1&0\\
0&1&0&0&0&1\\
-1&0&0&0&0&0\\
0&-1&0&2&0&0\\
0&0&-1&0&1&0
\end{pmatrix}
\begin{pmatrix}A_{n}\\B_{n}\\C_{n}\\D_{n}\\E_{n}\\F_{n}\end{pmatrix} $$
So, by induction:
$$\begin{pmatrix}A_{n}\\B_{n}\\C_{n}\\D_{n}\\E_{n}\\F_{n}\end{pmatrix}= \begin{pmatrix}0&0&0&1&0&0\\
2&0&0&0&1&0\\
0&1&0&0&0&1\\
-1&0&0&0&0&0\\
0&-1&0&2&0&0\\
0&0&-1&0&1&0
\end{pmatrix}^n\begin{pmatrix}1\\0\\0\\0\\0\\0\end{pmatrix}$$
So now you need to know how to do exponentiation of a matrix. Turns out, the characteristic polynomial of this matrix is a very simple $(1+x^2)^3$, so the roots are $i$ and $-i$ and that means we know we can write:
$$A_n = p_A(n)i^n + q_A(n)(-i)^n$$
where $p_A$ and $q_A$ are polynomials of degree $2$ or less. So we can solve for $p_A$ and $p_B$ by using the first six values of $A_n$.
Similarly, there are polynomials $p_B,q_B,p_C,q_C$, etc.
A: If the goal is to use Leibnitz's Rule here, we note that for $k>2$
$$\frac{d^k\,x^2}{dx^k}=0$$
Thus, we have
$$\begin{align}
\frac{d^n}{dx^n}(x^2\cos x)&=\sum_{k=0}^n\binom{n}{k}\frac{d^k\,x^2}{dx^k}\frac{d^{n-k}\cos x}{dx^{n-k}}\\\\
&=\sum_{k=0}^2\binom{n}{k}\frac{d^k\,x^2}{dx^k}\frac{d^{n-k}\cos x}{dx^{n-k}}\\\\
&=\binom{n}{0}\frac{d^0\,x^2}{dx^0}\frac{d^{n}\cos x}{dx^{n}}\\\\
&+\binom{n}{1}\frac{d\,x^2}{dx}\frac{d^{n-1}\cos x}{dx^{n-1}}\\\\
&+\binom{n}{2}\frac{d^2\,x^2}{dx^2}\frac{d^{n-2}\cos x}{dx^{n-2}}\\\\
&=x^2\cos (x+n\pi/2)+nx\sin(x+n\pi/2)-n(n-1)\cos (x+n\pi/2) \tag 1
\end{align}$$
where we used the relationship $\frac{d^n\,\cos x}{dx^n}=\cos (x+n\pi/2)$ in arriving at $(1)$.  This can be seen by writing
$$\begin{align}
\frac{d^n\,\cos x}{dx^n}&=\frac{d^n}{dx^n}\text{Re}\left(e^{ix}\right)\\\\
&=\text{Re}\left(\frac{d^n\,e^{ix}}{dx^n}\right)\\\\
&=\text{Re}\left(i^n\,e^{ix}\right)\\\\
&=\text{Re}\left(e^{i(x+n\pi/2}\right)\\\\
&=\cos (x+n\pi/2)
\end{align}$$
A: The Leibniz formula only has a few terms. This is seen by the following.
\begin{align}
D^{n} y &= D^{n}\{ x^{2} \, \cos(ax)\} = \sum_{k=0}^{n} \binom{n}{k} \, D^{k}\{x^{2}\} \, D^{n-k}\{\cos(ax)\} 
\end{align} 
Since $D(x^{2}) = 2 x$, $D^{2}(x^{2}) = 2$, and $D^{3+m}(x^{2}) = 0$ for $m \geq 0$, then
\begin{align}
D^{n} y &= \binom{n}{0} \, D^{0}(x^{2}) \, D^{n}(\cos(ax)) + \binom{n}{1} \, D^{1}(x^{2}) \, D^{n-1}(\cos(ax)) + \binom{n}{2} \, D^{2}(x^{2}) \, D^{n-2}(\cos(ax)) \\
&= x^{2} \, D^{n}(\cos(ax)) + 2 n x \, D^{n-1}(\cos(ax)) + n(n-1) \, D^{n-2}(\cos(ax))
\end{align} 
For the case of $n$ being even then
\begin{align}
D^{2n} y &= (-1)^{n} \, a^{2n-2} \, \left[(a^{2} \, x^{2} - 2n(2n-1)) \, \cos(ax) + 4 a n x \, \sin(ax) \right]
\end{align} 
and for $n$ being odd
\begin{align}
D^{2n+1} y &= (-1)^{n+1} \, a^{2n-1} \, \left[ (a^{2} x^{2} + 2n(2n+1)) \, \sin(ax) - 2(2n+1) a x \cos(ax) \right]
\end{align}
A: 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}$$
