#### 2.21   ODE No. 21

$y'(x)-y(x)^2+y(x) \sin (x)-\cos (x)=0$ Mathematica : cpu = 0.322139 (sec), leaf count = 7

$\{\{y(x)\to \sin (x)\}\}$ Maple : cpu = 0.103 (sec), leaf count = 25

$\left \{ y \left ( x \right ) =-{\frac {{{\rm e}^{-\cos \left ( x \right ) }}}{{\it \_C1}+\int \!{{\rm e}^{-\cos \left ( x \right ) }}\,{\rm d}x}}+\sin \left ( x \right ) \right \}$

Hand solution

\begin {align} y^{\prime }-y^{2}+y\sin \left ( x\right ) -\cos \left ( x\right ) & =0\nonumber \\ y^{\prime } & =y^{2}-y\sin \left ( x\right ) +\cos \left ( x\right ) \tag {1} \end {align}

This is Riccati ﬁrst order non-linear ODE of the form of the general form $$y^{\prime }=P\left ( x\right ) +Q\left ( x\right ) y+R\left ( x\right ) y^{2}$$ where $$P\left ( x\right ) =\cos \left ( x\right ) ,Q\left ( x\right ) =-\sin \left ( x\right ) ,R\left ( x\right ) =1$$. It is best to ﬁrst try to spot a particular solution $$y_{p}$$ and use the transformation $$y=y_{p}+\frac {1}{u}$$ otherwise we use $$y=-\frac {u^{\prime }}{yR\left ( x\right ) }$$ transformation. For this problem $y_{p}=\sin \left ( x\right )$ Therefore

\begin {align*} y & =\sin x+\frac {1}{u}\\ y^{\prime } & =\cos x-\frac {u^{\prime }}{u^{2}} \end {align*}

Equating this to (1) gives

\begin {align*} y^{2}-y\sin \left ( x\right ) +\cos \left ( x\right ) & =\cos x-\frac {u^{\prime }}{u^{2}}\\ \left ( \sin x+\frac {1}{u}\right ) ^{2}-\left ( \sin x+\frac {1}{u}\right ) \sin x+\cos x & =\cos x-\frac {u^{\prime }}{u^{2}}\\ \sin ^{2}x+\frac {1}{u^{2}}+\frac {2}{u}\sin x-\sin ^{2}x-\frac {1}{u}\sin x & =-\frac {u^{\prime }}{u^{2}}\\ \frac {1}{u^{2}}+\frac {1}{u}\sin x & =-\frac {u^{\prime }}{u^{2}}\\ 1+u\sin x & =-u^{\prime }\\ u^{\prime }+u\sin x & =-1 \end {align*}

Integrating factor is $$e^{\int \sin x}=e^{-\cos x}$$, hence

$d\left ( e^{-\cos x}u\right ) =-e^{-\cos x}$

Integrating both sides

\begin {align*} e^{-\cos x}u & =-{\displaystyle \int } e^{-\cos x}dx+C\\ u & =e^{\cos x}\left ( C-{\displaystyle \int } e^{-\cos x}dx\right ) \end {align*}

Since $$y=\sin x+\frac {1}{u}$$ then

$y=\sin x+\frac {e^{-\cos x}}{C-{\displaystyle \int } e^{-\cos x}dx}$

Or letting $$C_{1}=-C$$ to make match Maple form, we obtain

$y=-\frac {e^{-\cos x}}{C_{1}+{\displaystyle \int } e^{-\cos x}dx}+\sin x$