<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] The mistake is
$$v'=\sin\sqrt{x}\,dx \to  v=\int \sin\sqrt{x}\,dx\neq -\cos\sqrt{x}+k, \quad k\in \Bbb R$$
$$\int \sin\sqrt{x}\,dx=2\left(-\sqrt{x}\cos \left(\sqrt{x}\right)+\sin \left(\sqrt{x}\right)\right)+k',\quad k'\in \Bbb R$$
</s>