Solving $x'-2xt=2te^{2t}$ I just started studying differential equations, and I can't solve the following:
$$x'-2xt=2te^{2t}$$
I know it is a linear ordinary differential equation, and to solve it I have to  do the change of variables $x=ce^{\int_{t_0}^{t}2s ds}$. I want to find the general solution, so I can't subsitute $t_0$ for any value like $0$ or $1$. If I was given the value of the function for a $t_0$, meaning: $x(t_0)=x_0$. I would know how to proceed. What can I do? 
 A: Mutliply the equation by $e^{-t^2}$
$$x'-2xt=2te^{2t}$$
$$x'e^{-t^2}-2te^{-t^2}x=2te^{2t-t^2}$$
$$(xe^{-t^2})'=2te^{2t-t^2}$$
Integrate
$$xe^{-t^2}=2 \int te^{2t-t^2}dt +K$$
$$x(t)=2e^{t^2} \int te^{2t-t^2}dt +Ke^{t^2}$$
You can evaluate the integral with the error function or keep that way
$$x(t)= { \sqrt {\pi}}e^{t^2+1} \text {erf} (t-1)-e^{2t} +Ke^{t^2}$$
where 
$$\text {erf }(x)=\frac 2{\sqrt {\pi}}\int_0^x e^{-t^2} dt$$
A: Your ODE in the form of 
\begin{equation}
 x' + p(t)x = q(t)
\end{equation}
has the general solution is 
\begin{equation}
 x(t) 
 = 
 \frac{\int e^{\int p(t)}q(t) dt + C}{e^{\int p(t)}}
\end{equation}
where in your case, you have
\begin{align}
 p(t) &= -2t \\
 q(t) &= 2te^{2t}
\end{align}
The integration of $p(t)$ is
\begin{equation}
 \int p(t) = -t^2
\end{equation}
and hence
\begin{equation}
 x(t) 
 = 
 \frac{2\int te^{-t^2+2t} dt + C}{e^{-t^2}} \tag{1}
\end{equation}
Notice that
\begin{equation}
 \int te^{-t^2+2t} dt
 ={\displaystyle\int}\left(t-1\right)\mathrm{e}^{2t-t^2}\,\mathrm{d}t+{\displaystyle\int}\mathrm{e}^{2t-t^2}\,\mathrm{d}t
\end{equation}
The first integral is easy $\int f'e^{f} = e^{f}$and will give you 
\begin{equation}
 {\displaystyle\int}\left(t-1\right)\mathrm{e}^{2t-t^2}\,\mathrm{d}t
 =-\dfrac{\mathrm{e}^{2t-t^2}}{2}
\end{equation}
Now solving ${\displaystyle\int}\mathrm{e}^{2t-t^2}\,\mathrm{d}t$, you can complete the squares as such 
$${\displaystyle\int}\mathrm{e}^{2t-t^2}\,\mathrm{d}t={\displaystyle\int}\mathrm{e}^{1-\left(t-1\right)^2}\,\mathrm{d}t$$
Then do a change of variab;e $u = t-1$, to get
\begin{equation}
 {\displaystyle\int}\mathrm{e}^{2t-t^2}\,\mathrm{d}t=
 =\dfrac{\sqrt{{\pi}}\mathrm{e}\operatorname{erf}\left(u\right)}{2}
 =\dfrac{\sqrt{{\pi}}\mathrm{e}\operatorname{erf}\left(t-1\right)}{2}
\end{equation}
Finally, we get
\begin{equation}
 \int te^{-t^2+2t} dt
 =\dfrac{\sqrt{{\pi}}\mathrm{e}\operatorname{erf}\left(t-1\right)-\mathrm{e}^{2t-t^2}}{2}+C
\end{equation}

Replacing it in $(1)$, we get
  \begin{equation}
 x(t) 
 = 
 \frac{-e\sqrt{\pi} \operatorname{erf}(1-t) - e^{-t(t-2)}+C} {e^{-t^2}}
\end{equation}
Now, you can substitute $t_0$, to get the $C$, if you wish.

A: Using a standard method of finding an integrating factor one considers 
$$\frac{1}{\mu} \, \frac{d}{dt} \left( \mu \, y(t) \right) = y' + \left(\frac{d \, \ln \mu}{dt} \right) \, y.$$
Using this and comparing it to the differential equation in question one has 
$$\frac{d \, \ln \mu}{dt} = - 2 t = \frac{d(-t^2)}{dt},$$
or $\mu = e^{-t^2}$. Now,
\begin{align}
y' - 2 t \, y &= 2 t \, e^{2 t} \\
e^{t^2} \, D\left(e^{-t^2} \, y \right) &= 2t \, e^{2t} \\
D\left(e^{-t^2} \, y\right) &= 2t \, e^{2t - t^2}
\end{align}
and leads to 
$$y(t) = e^{t^2} \, \int^{t} 2u \, e^{- (u^2 - 2u)} \, du + c_{0}.$$
By completing the integration it can be shown that
$$y(t) = c_{1} - e^{2 t} - \sqrt{\pi} \, e^{t^2 + 1} \, erf(1-t),$$
where $erf(x)$ is the error function.
