An intriguing definite integral: $\int_{\pi/4}^{\pi/2} \frac{x^2+8}{(x^2-16)\sin (x) + 8 x \cos(x)} \ dx$ I need some hints, suggestions for the following integral
$$\int_{\pi/4}^{\pi/2} \frac{x^2+8}{(x^2-16)\sin (x) + 8 x \cos(x)} \ dx$$
Since it's a high school problem, I thought of some variable change, integration by parts, but I can't see yet how to make them work. I don't know where I should start from. Thanks!
 A: Let $u = 2\tan^{-1}\left(\frac{x}{4}\right) - x$. Then
$$ du = -\frac{x^2 + 8}{x^2 + 16}\,dx. $$
Now since
$$ \begin{align*}
\frac{x^2 + 8}{(x^2 - 16)\sin x + 8x \cos x} 
&= \frac{\frac{x^2 + 8}{x^2 + 16}}{\frac{8x}{16+x^2} \cos x - \frac{16-x^2}{16+x^2}\sin x} \\
&= \frac{\frac{x^2 + 8}{x^2 + 16}}{\sin\left(2\tan^{-1}\left(\frac{x}{4}\right)\right) \cos x - \cos\left(2\tan^{-1}\left(\frac{x}{4}\right)\right)\sin x} \\
&= \frac{\frac{x^2 + 8}{x^2 + 16}}{\sin\left(2\tan^{-1}\left(\frac{x}{4}\right) - x\right)} \\
&= -\frac{1}{\sin u}\frac{du}{dx},
\end{align*}$$
it remains to take integration by substitution.
A: Following up on Blue's comment:
In general
$$
a\sin x+b\cos x = \sqrt{a^2+b^2}\Big( \frac{a}{\sqrt{a^2+b^2}}\sin x + \frac{b}{\sqrt{a^2+b^2}}\cos x \Big) = \sqrt{a^2+b^2} \left(\cos\varphi\sin x+\sin\varphi\cos x\right) = \sqrt{a^2+b^2}\sin(x+\varphi),
$$
so $\tan\varphi = \dfrac b a$.
Now putting in $a=x^2-16$ and $b=8x$, we have
$$
\begin{align}
\Big( x^2 - 16 \Big)^2 + \Big(8x\Big)^2 & = \Big(x^4 - 32x^2 + 256\Big) + \Big(64x^2\Big) \\[10pt]
& = x^4 + 32x^2 + 256 = \Big( x^2 + 16 \Big)^2
\end{align}
$$
Therefore
$$
(x^2-16)\sin x + 8x\cos x = (x^2+16)\sin(x+\varphi)
$$
where
$$
\varphi = \arctan\frac{8x}{x^2-16}. \tag{1}
$$
The answer from sos440 doesn't explain how s/he thought of that susbstitution in the first place, but conjoining that with $(1)$, I'm thinking: let's see if that last fraction in $(1)$ is the tangent of a double angle.  Remember that
$$
\tan(2\alpha) = \frac{2\tan\alpha}{1-\tan^2\alpha}.
$$
Therefore
$$
\frac{8x}{x^2-16} = \frac{2(-x/4)}{1-(-x/4)^2} = \tan(2\alpha)\text{ where } \tan\alpha = \frac{-x}{4}.
$$
After that, proceed as in the answer from sos440.
A: Let $R\sin A=x^2-16$  and $R\cos A=8x\implies R=x^2+16$  and $\cos A=\frac{8x}{x^2+16}$
So, $(x^2-16)\sin x+8x\cos x$
$=(x^2+16)(\cos A \cos x+\sin A\sin x)$
$=(x^2+16)\cos (x-A)$
$=(x^2+16)\cos(x-\cos^{-1}(\frac{8x}{x^2+16}))$
Putting $y=x-\cos^{-1}(\frac{8x}{x^2+16})$, we get $\frac{dy}{dx}=\frac{x^2+8}{x^+16}$
$$\int\frac{x^2+8}{(x^2-16)\sin (x) + 8 x \cos(x)} \ dx$$
$$=\int\frac{x^2+8}{(x^2-16)\cos(x-\cos^{-1}(\frac{8x}{x^2+16}))} \ dx$$
$$=\int\frac{dy}{\mathrm{cos}y}=\int \sec ydy=\ln|\sec y+ \tan y|+C=\ln\tan (\frac{\pi}{4}+\frac{y}{2})+C$$  where C is  the indeterminate constant for indefinite integral.
Now if $2B=\cos^{-1}(\frac{8x}{x^2+16}),\frac{8x}{x^2+16}=\cos2B$
$=\frac{1-\tan^2B}{1+\tan^2B}\implies \tan^2B=(\frac{4+x}{4-x})^2$
$y=x-2\tan^{-1}(\frac{4+x}{4-x})=x-2(\frac{\pi}{4}+\tan^{-1}(\frac{x}{4})) $
When $x=\frac{\pi}{2}, y=-2\tan^{-1}\frac{\pi}{8}$
When $x=\frac{\pi}{4}, y=-\frac{\pi}{4}-2\tan^{-1}\frac{\pi}{16}$
