Solve the differential equation: $ y' + y\cos x = \frac{1}{2} \sin2x$ I tried doing:
$$ y' + y \cos x = 0 $$
$$ \frac{dy}{dx} = -y \cos x$$
$$ -\int \frac{1}{y}\,dy = \int \cos x \,dx $$
$$ -\ln y = \sin x +C $$
$$ y = \frac {1}{c(x) e^{\sin x}} $$
Now I should calculate $y'$ and insert $y$ and $y'$ to the $ y' + y\cos x = \frac{1}{2} \sin2x$
When I try to do this:
$$ \sin x \cos x = \frac{-c'(x)}{c^2(x)^{\sin x}} $$
What should I do next?
 A: Using the method of integrating factor,
$$e^{\sin x}y'+ye^{\sin x}\cos x=\frac{1}{2}\sin 2x e^{\sin x}$$
$$\frac{d}{dx}\left(ye^{\sin x}\right)=\frac{1}{2}\sin 2x e^{\sin x}$$
$$ye^{\sin x}=\int\frac{1}{2}e^{\sin x}\sin 2xdx$$
$$=\int e^{\sin x}\sin x \cos x dx$$
$$=\int \sin x d(e^{\sin x})$$
$$=\sin x e^{\sin x}-\int e^{\sin x}d(\sin x)$$
$$=\sin x e^{\sin x}-e^{\sin x}+C$$
Therefore,
$$y=\sin x-1+Ce^{-\sin x}$$
A: Have you heard of the integrating factor method? We have $$\frac{dy}{dx}+y\cos(x)=\frac{1}{2}\sin(2x)$$ Now multiply both sides by $e^{\sin(x)}$: $$e^{\sin(x)}\frac{dy}{dx}+ye^{\sin(x)}\cos(x)=\frac{1}{2}e^{\sin(x)}\sin(2x)$$ Using the product rule, the LHS simplifies to $$e^{\sin(x)}\frac{dy}{dx}+ye^{\sin(x)}\cos(x)=\frac{d}{dx}\left(ye^{\sin(x)}\right)$$ Thus $$\frac{d}{dx}\left(ye^{\sin(x)}\right)=\frac{1}{2}e^{\sin(x)}\sin(2x)$$ Integrating both sides, 
$$ye^{\sin(x)}=\int \frac{1}{2}e^{\sin(x)}\sin(2x)\,dx$$
$$ye^{\sin(x)}=e^{\sin(x)}(\sin(x)-1)+C$$
$$y=(\sin(x)-1)+Ce^{-\sin(x)}$$
In general, if you have a differential equation of the form
$$y'+y\cdot R(x)=B(x)$$ it is generally solved by multiplying both sides by $\displaystyle e^{\int R(x)\,dx}$.
Edit: Sorry, didn't realize that someone else answered the question right before me.
A: Here is a "reductio in absurdum" approach:
$$y' + y\cos(x)= \sin(x)\cos(x)$$
$$y' = \cos(x)(\sin(x)-y)$$
now set $\sin(x)-y = z$, we get $\cos(x)-y' = z'$
$$\cos(x)-z' = \cos(x)z$$
$$z' = \cos(x)(1-z)$$
now let $1-z=a, -z'=a'$,  $-a' = \cos(x)a$ 
$a' = -\cos(x)a$
Now bear in mind the chain rule and pretend $-\cos(x)$ is the inner detivative to $a$. Then the outer function would satisfy $a' = a$ that would be $a = \exp(g(x))$ for some function $g(x)$ having a detivative being $-\cos(x)$, and $\sin(x)+C$ has that derivative. Now what remains is to unroll the loop and identify.
