<s>[INST] $n$-th derivative of $f(x)=x\cos(x)$ Can someone help me prove that the $n$-th derivative of $f(x)=x\cos(x)$ is:
$$f^n(x)=x\cos\left(x+\frac{n\pi}{2}\right)+n\cos\left(x+(n-1)\frac{\pi}{2}\right)?$$
Thanks, and stay safe.
 [/INST] Just using induction using the product rule:
$f(x) = x\cos x$ so
$f'(x) = \cos x + x(-\sin x) = \cos x - x\sin x$
$f^2(x) = -\sin x - \sin x - x\cos x= -2\sin x - x\cos x$
$f^3(x) = -2\cos x-\cos x - x(-\sin x) = -3\sin x +x\sin x$.
By pattern recognition we sort of see that $f^n = \pm n \operatorname{trig} x \pm x\operatorname{other\ trig} x$.  Bearing in mind that $\sin x = \cos (\frac \pi 2 - x)$ and that the pattern of the $\pm$ has a periodicity of $4$ and so on we can see that
$f^n(x) =\pm n \operatorname{trig} x \pm x\operatorname{other\ trig} x=$
$x\cos(x+\frac{n\pi}{2})+n\cos(x+(n-1)\frac{\pi}{2})$
and we can feel grateful that someone else hammered the details and fine polished it for us.
But we have to verify it.
For $n= 0$ this fits
$f(x)  = x\cos x = x\cos(x+\frac{0\pi}{2})+0\cos(x+(0-1)\frac{\pi}{2})$
No question of that.
And for $n=1$ we have
$f'(x) =  \cos x - x\sin x= x\cos(x+\frac{1\pi}{2})+1\cos(x+(1-1)\frac{\pi}{2})$
$=1\cos (x + 0) + x\cos(x+\frac {\pi}2) = \cos x- x \sin x$.
It works.  Now to verify in general we must use induction.
If $f^k(x) =x\cos(x+\frac{k\pi}{2})+k\cos(x+(k-1)\frac{\pi}{2})$
then
$f^{k+1}(x) = \cos(x+\frac{k\pi}{2}) + x(-\sin(x+\frac{k\pi}2) -k\sin(x+(k-1)\frac \pi 2)=$
$=\cos(x+\frac{k\pi}{2}) +k\cos(x+k\frac {\pi}2) + x(\cos(x+\frac {(k+1)\pi}2))=$
$x\cos (x+\frac {(k+1)\pi}2)+ (k+1)\cos(x+k\frac \pi 2)$
So the result follows by induction.
</s>