I'm solving a first order differential equation.
$$\frac{dy}{dx}+2xy=x$$
I multiplied by the integration factor to get the equation in the form $f\left(x\right)\frac{dy}{dx}+f'\left(x\right)y=f\left(x\right)Q$
$$f\left(x\right)=e^{x^{2}}$$
so
$$e^{x^{2}}\frac{dy}{dx}+2xe^{x^{2}}y=xe^{x^{2}}$$
Rearranged
$$e^{x^{2}}y=\int{xe^{x^{2}}}dx$$
I know the easiest and correct way to do this is by using a u substitution for $e^{x^{2}}$ but I tried using integration by parts and I got a completely different answer to using a u sub.
I got $$y=\frac{1}{2}-\frac{1}{4x^{2}}+\frac{c}{e^{x^{2}}}$$
The correct answer using u sub is $$y=\frac{1}{2}+\frac{c}{e^{x^{2}}}$$
I don't understand why I'm getting a different answer.
If I take $u = x$ and $\frac{dv}{dx} = e^{x^{2}}$
Using integration by parts I get $$\int{xe^{x^{2}}}=x\left(\frac{1}{2x}e^{x^{2}}\right)-\int\frac{1}{2x}e^{x^{2}}dx$$
Can anyone explain what am I doing wrong, or why this is getting me different answer? Or why can I not use to it to get the same answer?
Thank you to whoever can tell me what I'm doing wrong.
$$\int x e^{x^2}dx $$
Is immediate being the integrand in the form $f' e ^f$.
$$\frac{1}{2}\int 2x e^{x^2}dx =\frac{1}{2}e^{x^2}$$