TITLE: How To Solve a Trigonometric Differential Equation
QUESTION [9 upvotes]: Salutations, I have been trying to approach an ODE with trigonometric functions that I found interesting:
$$y'+x\sin(2y)=xe^{-x^2}\cos^2(y)$$
I tried to find a result with wolfram web page (free version) and I got this one:
$$y=\arctan\left(\frac{1}{2}e^{-x^2}(c+x^2)\right)$$
I have tried to approach this exercise by substitution of variables, also separable variables and I have not had luck by power series, 
and I do not know if methods like those of Ricatti and Bernoulli are appropriate for this case.
This is just for academic curiosity and I would like to understand better this kind of ODEs. So, I require any guidance or starting steps or explanations about how to approach this kind of exercises.
Thanks for your attention.

REPLY [3 votes]: When I saw the equation which contains $\sin(2y)$ and $\cos^2(y)$, I immediately thought about the tangent hal-angle subsitution (let us call that intuition).
So, let $y=\tan ^{-1}(z)$ which reduces the equation to
$$z'+2 x z=e^{-x^2} x$$ The homogeneous part is simple
$$z'+2 x z=0 \implies z=C \,e^{-x^2}$$
Now, variation of parameters to get 
$$C'=x \implies C=\frac 12 x^2+c_1\implies z=e^{-x^2}\left(\frac 12 x^2+c_1 \right)$$ and, finally, the solution.