<s>[INST] Failing a basic integration exercise; where did I go wrong? (This is a basic calculus exercise gone wrong where I need some feedback to get forward.)
I've attempted to calculate an integral by first integrating it by parts and then by substituting. The result I got is not correct though. Can I get a hint about where started to make mistakes?
Here are my steps:
$$\int \sqrt{x}\cdot\sin\sqrt{x}\,dx$$

*

*Applying integration by parts formula
$$\int uv' \, dx = uv - \int u'v \, dx$$
where $u=\sqrt{x}$, $v'=\sin\sqrt{x}$, $u'=\frac{1}{2\sqrt{x}}$ and $v=-\cos\sqrt{x}$, resulting in:
$$\int \sqrt{x}\cdot\sin\sqrt{x}\,dx = \sqrt{x} \cdot -\cos\sqrt{x} - \int \frac{1}{2\sqrt{x}} \cdot -\cos\sqrt{x} \, dx$$


*Next, I tried substituting $x$ with $g(t)=t^2$ in the remaining integral, i. e. replacing each $x$ in the integral with $t^2$ and the ending $dx$ with $g'(t)=2t\,dt$. I would later bring back the $x$ by substituting $t=\sqrt{x}$ after integration. Continuing from where we left by substituting:
$$\sqrt{x} \cdot -\cos\sqrt{x} - \int \frac{1}{2\sqrt{x}} \cdot -\cos\sqrt{x} \, dx$$
$$\Longrightarrow \sqrt{x} \cdot -\cos\sqrt{x} - \int \frac{1}{2\sqrt{t^2}} \cdot -\cos\sqrt{t^2}\cdot2t \, dt$$


*Then I pulled out the constant multipliers from the integral:
$$\sqrt{x} \cdot -\cos\sqrt{x} - \frac{1}{2} \cdot -1 \cdot 2 \int \frac{1}{\sqrt{t^2}} \cdot \cos\sqrt{t^2}\cdot t \, dt$$
which turned out to eliminate each other (resulting in just $\cdot1$), so we end up with:
$$\sqrt{x} \cdot -\cos\sqrt{x} \cdot \int \frac{1}{\sqrt{t^2}} \cdot \cos\sqrt{t^2}\cdot t \, dt$$


*Reducing the integrand by reducing $\frac{1}{\sqrt{t^2}}\Rightarrow\frac{1}{t}$, which again is eliminated by multiplying with the integrand's $t$, and reducing $\cos\sqrt{t^2}\Rightarrow\cos t$. Therefore resulting in:
$$\sqrt{x} \cdot -\cos\sqrt{x} \cdot \int \cos t \, dt$$
where the integral can be solved as $\int \cos t \, dt = \sin t + C$. So now we are at:
$$\sqrt{x} \cdot -\cos\sqrt{x} \cdot \sin t + C$$
The correct answer however is
$$\int \sqrt{x} \sin\sqrt{x} \, dx = 4 \sqrt{x} \sin\sqrt{x} - 2 (x - 2) \cos\sqrt{x} + C$$
So something somewhere in my process went horribly wrong. What?
 [/INST] After the substitution $u = \sqrt{x}$, the integral becomes $2\int u^2 \sin(u) \ du$ as Adam Rubinson has said. We can proceed using tabular integration:
$$\begin{array}{c|c} u^2  & \sin(u) \\ \hline 2u & -\cos(u) \\ \hline \ 2 & -\sin(u) \\ \hline \ 0 & \cos(u)\end{array}$$
where we differentiate on the left and integrate on the right, and multiply the terms diagonally (the signs alternate).
Hence $2\int u^2 \sin(u) \ du = 2 \left(-u^2 \cos(u) - -2u \sin(u) + 2\cos(u) \right) + C$, which is:
$$2 \left( -x \cos( \sqrt x )+2\sqrt x \sin(\sqrt x) + 2\cos(\sqrt x)\right)+C = 4 \sqrt{x} \sin(\sqrt x) - 2(x-2)\cos (\sqrt x) +C$$
</s>