Evaluating the improper integral $\int_0^\infty \frac{x\cos x-\sin x}{x^3} \cos(\frac{x}{2}) \mathrm dx $
Solution 1:
$\newcommand{\bbx}[1]{\,\bbox[8px,border:1px groove navy]{{#1}}\,} \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace} \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack} \newcommand{\dd}{\mathrm{d}} \newcommand{\ds}[1]{\displaystyle{#1}} \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,} \newcommand{\ic}{\mathrm{i}} \newcommand{\mc}[1]{\mathcal{#1}} \newcommand{\mrm}[1]{\mathrm{#1}} \newcommand{\pars}[1]{\left(\,{#1}\,\right)} \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}} \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,} \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}} \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$ \begin{align} &\int_{0}^{\infty}{x\cos\pars{x} - \sin\pars{x} \over x^{3}}\, \cos\pars{x \over 2}\,\dd x \\[5mm] = & \int_{0}^{\infty}{x\bracks{1 - 2\sin^{2}\pars{x/2}} - \sin\pars{x} \over x^{3}}\,\cos\pars{x \over 2}\,\dd x \\[5mm] & = {1 \over 2}\int_{0}^{\infty}{2x\cos\pars{x/2} - 2x\sin\pars{x}\sin\pars{x/2} - 2\sin\pars{x}\cos\pars{x/2} \over x^{3}}\,\,\,\dd x \\[5mm] & = {1 \over 2}\int_{0}^{\infty}{x\cos\pars{x/2} + x\cos\pars{3x/2} - \sin\pars{3x/2} - \sin\pars{x/2} \over x^{3}}\,\,\,\dd x \\[1cm] & = -\,{1 \over 2}\int_{0}^{\infty}{1 - \cos\pars{x/2} \over x^{2}}\,\dd x - {1 \over 2}\int_{0}^{\infty}{1 - \cos\pars{3x/2} \over x^{2}}\,\dd x \\[5mm] & - {1 \over 4}\int_{x\ =\ 0}^{x\ \to\ \infty}\bracks{2x - \sin\pars{3x/2} - \sin\pars{x/2}}\,\dd\pars{1 \over x^{2}} \end{align}
Integrating by parts the last integral: \begin{align} &\int_{0}^{\infty}{x\cos\pars{x} - \sin\pars{x} \over x^{3}}\, \cos\pars{x \over 2}\,\dd x = \\[5mm] & = -\,{1 \over 2}\int_{0}^{\infty}{1 - \cos\pars{x/2} \over x^{2}}\,\dd x - {1 \over 2}\int_{0}^{\infty}{1 - \cos\pars{3x/2} \over x^{2}}\,\dd x \\[5mm] & + {1 \over 4}\int_{x = 0}^{\infty}{2 - 3\cos\pars{3x/2}/2 - \cos\pars{x/2}/2 \over x^{2}}\,\dd x \\[1cm] & = -\,{1 \over 2}\int_{0}^{\infty}{1 - \cos\pars{x/2} \over x^{2}}\,\dd x - {1 \over 2}\int_{0}^{\infty}{1 - \cos\pars{3x/2} \over x^{2}}\,\dd x \\[5mm] & + {3 \over 8}\int_{0}^{\infty}{1 - \cos\pars{3x/2} \over x^{2}}\,\dd x + {1 \over 8}\int_{0}^{\infty}{1 - \cos\pars{x/2} \over x^{2}}\,\dd x \\[1cm] & = -\,{3 \over 8}\int_{0}^{\infty}{1 - \cos\pars{x/2} \over x^{2}}\,\dd x -\,{1 \over 8}\int_{0}^{\infty}{1 - \cos\pars{3x/2} \over x^{2}}\,\dd x \\[5mm] & = -\,{3 \over 16}\int_{0}^{\infty}{1 - \cos\pars{x} \over x^{2}}\,\dd x -\,{3 \over 16}\int_{0}^{\infty}{1 - \cos\pars{x} \over x^{2}}\,\dd x = -\,{3 \over 8}\ \int_{0}^{\infty}{1 - \cos\pars{x} \over x^{2}}\,\dd x \\[5mm] & = -\,{3 \over 4}\int_{0}^{\infty}{\sin^{2}\pars{x/2} \over x^{2}}\,\dd x = -\,{3 \over 8}\ \underbrace{\int_{0}^{\infty}{\sin^{2}\pars{x} \over x^{2}}\,\dd x} _{\ds{=\ {\pi \over 2}}}\ = \ \bbox[#ffe,10px,border:1px dotted navy]{\ds{-\,{3 \over 16}\,\pi}} \end{align} >By integrating by parts: $\ds{\int_{0}^{\infty}{\sin^{2}\pars{x} \over x^{2}}\,\dd x = \int_{0}^{\infty}{\sin\pars{x} \over x}\,\dd x = {1 \over 2}\,\pi}$.
Solution 2:
$$
\begin{align}
&\int_0^\infty\frac{x\cos(x)-\sin(x)}{x^3}\cos\left(\frac{x}{2}\right)\,\mathrm{d}x\tag{1}\\
&=\int_0^\infty\frac{x\left(\cos\left(\frac32x\right)+\cos\left(\frac12x\right)\right)-\left(\sin\left(\frac32x\right)+\sin\left(\frac12x\right)\right)}{2x^3}\,\mathrm{d}x\tag{2}\\
&=-\int_0^\infty\frac{x\left(\cos\left(\tfrac32x\right)+\cos\left(\tfrac12x\right)\right)-\left(\sin\left(\tfrac32x\right)+\sin\left(\tfrac12x\right)\right)}{4}\,\mathrm{d}x^{-2}\tag{3}\\
&=\int_0^\infty\frac{\left(\frac12\cos\left(\frac12x\right)-\frac12\cos\left(\frac32x\right)\right)-x\left(\frac32\sin\left(\frac32x\right)+\frac12\sin\left(\frac12x\right)\right)}{4x^2}\,\mathrm{d}x\tag{4}\\
&=\int_0^\infty\left(\frac{1-\cos\left(\frac32x\right)}{8x^2}-\frac{1-\cos\left(\frac12x\right)}{8x^2}-\frac{3\sin\left(\frac32x\right)}{8x}-\frac{\sin\left(\frac12x\right)}{8x}\right)\mathrm{d}x
\tag{5}\\
&=\int_0^\infty\left(\frac{3(1-\cos(x))}{16x^2}-\frac{1-\cos(x)}{16x^2}-\frac{3\sin(x)}{8x}-\frac{\sin(x)}{8x}\right)\mathrm{d}x
\tag{6}\\
&=\int_0^\infty\left(\frac{3\sin(x)}{16x}-\frac{\sin(x)}{16x}-\frac{3\sin(x)}{8x}-\frac{\sin(x)}{8x}\right)\mathrm{d}x
\tag{7}\\
&=-\frac38\int_0^\infty\frac{\sin(x)}{x}\,\mathrm{d}x\tag{8}\\
&=-\frac{3\pi}{16}\tag{9}
\end{align}
$$
Explanation:
$(2)$: trigonometric product formulas
$(3)$: prepare to integrate by parts
$(4)$: integrate by parts
$(5)$: separate integrals
$(6)$: substitute $x\mapsto2x$ and $x\mapsto\frac23x$
$(7)$: integrate by parts
$(8)$: combine
$(9)$: $\int_0^\infty\frac{\sin(x)}{x}\,\mathrm{d}x=\frac\pi2$
Solution 3:
We can also use contour integration.
$$ \begin{align} &\int_{0}^{\infty} \frac{x \cos x - \sin x}{x^{3}} \, \cos \left(\frac{x}{2} \right) \, dx \\ &= \frac{1}{2} \int_{-\infty}^{\infty} \frac{x \left(\frac{e^{ix}+e^{-ix}}{2} \right) -\frac{e^{ix}-e^{-ix}}{2i}}{x^{3}} \left(\frac{e^{ix/2}+e^{-ix/2}}{2} \right) \, dx \\ &= \frac{1}{2} \lim_{\epsilon \to 0^{+}} \int_{-\infty}^{\infty} \frac{x \left(\frac{e^{ix}+e^{-ix}}{2} \right) -\frac{e^{ix}-e^{-ix}}{2i}}{(x- i \epsilon)^{3}} \left(\frac{e^{ix/2}+e^{-ix/2}}{2} \right) \, dx \\ &= \frac{1}{8} \lim_{\epsilon \to 0^{+}} \int_{-\infty}^{\infty}\frac{(x+i)(e^{3ix/2}+e^{ix/2})}{(x- i\epsilon)^{3}} \, dx + \frac{1}{8} \lim_{\epsilon \to 0^{+}} \int_{-\infty}^{\infty} \frac{(x-i)(e^{-ix/2}+e^{-3ix/2})}{(x- i\epsilon)^{3}} \, dx \\ &=\frac{1}{8} \lim_{\epsilon \to 0^{+}} 2 \pi i \, \text{Res} \left[\frac{(z+i)(e^{3iz/2}+e^{iz/2})}{(z- i \epsilon)^{3}} , i\epsilon \right] + 0 \tag{1} \\ &= \frac{1}{8} \lim_{\epsilon \to 0^{+}} \, 2 \pi i \, \frac{1}{2!} \lim_{z \to i \epsilon}\frac{d^{2}}{dz^{2}} \, (z+i)(e^{3iz/2}+e^{iz/2}) \\ &= \frac{1}{8} \lim_{\epsilon \to 0^{+}} \frac{\pi}{4} \, e^{-3 \epsilon/2} \left((\epsilon-3) e^{\epsilon} + 9 \epsilon -3 \right) \\ &= - \frac{3 \pi}{16} \end{align}$$
$(1)$ The second integral vanishes since the function $ \displaystyle \frac{(z-i)(e^{-iz/2}+e^{-3iz/2})}{(z- i\epsilon)^{3}} $ is analytic in the lower half-plane where $\left| e^{iaz} \right| \le 1$ if $a \le 0$.