2.21   ODE No. 21

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


\[\{\{y(x)\to \sin (x)\}\}\] Maple : cpu = 0.171 (sec), leaf count = 25


\[y \relax (x ) = -\frac {{\mathrm e}^{-\cos \relax (x )}}{c_{1}+\int {\mathrm e}^{-\cos \relax (x )}d x}+\sin \relax (x )\]

Hand solution

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

This is Riccati first order non-linear ODE of the form of the general form \(y^{\prime }=P\relax (x) +Q\relax (x) y+R\relax (x) y^{2}\) where \(P\relax (x) =\cos \relax (x) ,Q\relax (x) =-\sin \relax (x) ,R\relax (x) =1\). It is best to first 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\relax (x) }\) transformation. For this problem \[ y_{p}=\sin \relax (x) \] 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 \relax (x) +\cos \relax (x) & =\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 \]