Solution (source code)

= Solution

An <integrating factor> for the <first-order linear differential equation> is $\mu(x)=e^{\sin x}$. Multiplication gives
$$
(ye^{\sin x})'=2\sin x\cos x\,e^{\sin x}.
$$
Substitute $u=\sin x$ in the <antiderivative>: $\int2u e^u\,du=2(u-1)e^u$. Therefore
$$
\boxed{y(x)=2\sin x-2+Ce^{-\sin x},\qquad C\in\mathbb R.}
$$
Differentiating verifies the equation everywhere on the real line; no division by $\cos x$ restricts the solution.