2.4.2 problem 2

Solved as first order linear ode
Solved as first order Exact ode
Maple step by step solution
Maple trace
Maple dsolve solution
Mathematica DSolve solution

Internal problem ID [18229]
Book : Elementary Differential Equations. By Thornton C. Fry. D Van Nostrand. NY. First Edition (1929)
Section : Chapter IV. Methods of solution: First order equations. section 31. Problems at page 85
Problem number : 2
Date solved : Monday, December 23, 2024 at 09:16:31 PM
CAS classification : [_linear]

Solve

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

Solved as first order linear ode

Time used: 0.119 (sec)

In canonical form a linear first order is

\begin{align*} y^{\prime } + q(x)y &= p(x) \end{align*}

Comparing the above to the given ode shows that

\begin{align*} q(x) &=\frac {1}{x}\\ p(x) &=\sin \left (x \right ) \end{align*}

The integrating factor \(\mu \) is

\begin{align*} \mu &= e^{\int {q\,dx}}\\ &= {\mathrm e}^{\int \frac {1}{x}d x}\\ &= x \end{align*}

The ode becomes

\begin{align*} \frac {\mathop {\mathrm {d}}}{ \mathop {\mathrm {d}x}}\left ( \mu y\right ) &= \mu p \\ \frac {\mathop {\mathrm {d}}}{ \mathop {\mathrm {d}x}}\left ( \mu y\right ) &= \left (\mu \right ) \left (\sin \left (x \right )\right ) \\ \frac {\mathop {\mathrm {d}}}{ \mathop {\mathrm {d}x}} \left (x y\right ) &= \left (x\right ) \left (\sin \left (x \right )\right ) \\ \mathrm {d} \left (x y\right ) &= \left (\sin \left (x \right ) x\right )\, \mathrm {d} x \\ \end{align*}

Integrating gives

\begin{align*} x y&= \int {\sin \left (x \right ) x \,dx} \\ &=\sin \left (x \right )-\cos \left (x \right ) x + c_1 \end{align*}

Dividing throughout by the integrating factor \(x\) gives the final solution

\[ y = \frac {\sin \left (x \right )-\cos \left (x \right ) x +c_1}{x} \]
Figure 2.43: Slope field plot
\(y^{\prime }+\frac {y}{x} = \sin \left (x \right )\)

Summary of solutions found

\begin{align*} y &= \frac {\sin \left (x \right )-\cos \left (x \right ) x +c_1}{x} \\ \end{align*}
Solved as first order Exact ode

Time used: 0.190 (sec)

To solve an ode of the form

\begin{equation} M\left ( x,y\right ) +N\left ( x,y\right ) \frac {dy}{dx}=0\tag {A}\end{equation}

We assume there exists a function \(\phi \left ( x,y\right ) =c\) where \(c\) is constant, that satisfies the ode. Taking derivative of \(\phi \) w.r.t. \(x\) gives

\[ \frac {d}{dx}\phi \left ( x,y\right ) =0 \]

Hence

\begin{equation} \frac {\partial \phi }{\partial x}+\frac {\partial \phi }{\partial y}\frac {dy}{dx}=0\tag {B}\end{equation}

Comparing (A,B) shows that

\begin{align*} \frac {\partial \phi }{\partial x} & =M\\ \frac {\partial \phi }{\partial y} & =N \end{align*}

But since \(\frac {\partial ^{2}\phi }{\partial x\partial y}=\frac {\partial ^{2}\phi }{\partial y\partial x}\) then for the above to be valid, we require that

\[ \frac {\partial M}{\partial y}=\frac {\partial N}{\partial x}\]

If the above condition is satisfied, then the original ode is called exact. We still need to determine \(\phi \left ( x,y\right ) \) but at least we know now that we can do that since the condition \(\frac {\partial ^{2}\phi }{\partial x\partial y}=\frac {\partial ^{2}\phi }{\partial y\partial x}\) is satisfied. If this condition is not satisfied then this method will not work and we have to now look for an integrating factor to force this condition, which might or might not exist. The first step is to write the ODE in standard form to check for exactness, which is

\[ M(x,y) \mathop {\mathrm {d}x}+ N(x,y) \mathop {\mathrm {d}y}=0 \tag {1A} \]

Therefore

\begin{align*} \left (x\right )\mathop {\mathrm {d}y} &= \left (\sin \left (x \right ) x -y\right )\mathop {\mathrm {d}x}\\ \left (-\sin \left (x \right ) x +y\right )\mathop {\mathrm {d}x} + \left (x\right )\mathop {\mathrm {d}y} &= 0 \tag {2A} \end{align*}

Comparing (1A) and (2A) shows that

\begin{align*} M(x,y) &= -\sin \left (x \right ) x +y\\ N(x,y) &= x \end{align*}

The next step is to determine if the ODE is is exact or not. The ODE is exact when the following condition is satisfied

\[ \frac {\partial M}{\partial y} = \frac {\partial N}{\partial x} \]

Using result found above gives

\begin{align*} \frac {\partial M}{\partial y} &= \frac {\partial }{\partial y} \left (-\sin \left (x \right ) x +y\right )\\ &= 1 \end{align*}

And

\begin{align*} \frac {\partial N}{\partial x} &= \frac {\partial }{\partial x} \left (x\right )\\ &= 1 \end{align*}

Since \(\frac {\partial M}{\partial y}= \frac {\partial N}{\partial x}\), then the ODE is exact The following equations are now set up to solve for the function \(\phi \left (x,y\right )\)

\begin{align*} \frac {\partial \phi }{\partial x } &= M\tag {1} \\ \frac {\partial \phi }{\partial y } &= N\tag {2} \end{align*}

Integrating (2) w.r.t. \(y\) gives

\begin{align*} \int \frac {\partial \phi }{\partial y} \mathop {\mathrm {d}y} &= \int N\mathop {\mathrm {d}y} \\ \int \frac {\partial \phi }{\partial y} \mathop {\mathrm {d}y} &= \int x\mathop {\mathrm {d}y} \\ \tag{3} \phi &= x y+ f(x) \\ \end{align*}

Where \(f(x)\) is used for the constant of integration since \(\phi \) is a function of both \(x\) and \(y\). Taking derivative of equation (3) w.r.t \(x\) gives

\begin{equation} \tag{4} \frac {\partial \phi }{\partial x} = y+f'(x) \end{equation}

But equation (1) says that \(\frac {\partial \phi }{\partial x} = -\sin \left (x \right ) x +y\). Therefore equation (4) becomes

\begin{equation} \tag{5} -\sin \left (x \right ) x +y = y+f'(x) \end{equation}

Solving equation (5) for \( f'(x)\) gives

\[ f'(x) = -\sin \left (x \right ) x \]

Integrating the above w.r.t \(x\) gives

\begin{align*} \int f'(x) \mathop {\mathrm {d}x} &= \int \left ( -\sin \left (x \right ) x\right ) \mathop {\mathrm {d}x} \\ f(x) &= \cos \left (x \right ) x -\sin \left (x \right )+ c_1 \\ \end{align*}

Where \(c_1\) is constant of integration. Substituting result found above for \(f(x)\) into equation (3) gives \(\phi \)

\[ \phi = x y +\cos \left (x \right ) x -\sin \left (x \right )+ c_1 \]

But since \(\phi \) itself is a constant function, then let \(\phi =c_2\) where \(c_2\) is new constant and combining \(c_1\) and \(c_2\) constants into the constant \(c_1\) gives the solution as

\[ c_1 = x y +\cos \left (x \right ) x -\sin \left (x \right ) \]

Solving for \(y\) gives

\begin{align*} y &= -\frac {\cos \left (x \right ) x -\sin \left (x \right )-c_1}{x} \\ \end{align*}
Figure 2.44: Slope field plot
\(y^{\prime }+\frac {y}{x} = \sin \left (x \right )\)

Summary of solutions found

\begin{align*} y &= -\frac {\cos \left (x \right ) x -\sin \left (x \right )-c_1}{x} \\ \end{align*}
Maple step by step solution
\[ \begin {array}{lll} & {} & \textrm {Let's solve}\hspace {3pt} \\ {} & {} & y^{\prime }+\frac {y}{x}=\sin \left (x \right ) \\ \bullet & {} & \textrm {Highest derivative means the order of the ODE is}\hspace {3pt} 1 \\ {} & {} & y^{\prime } \\ \bullet & {} & \textrm {Solve for the highest derivative}\hspace {3pt} \\ {} & {} & y^{\prime }=-\frac {y}{x}+\sin \left (x \right ) \\ \bullet & {} & \textrm {Group terms with}\hspace {3pt} y\hspace {3pt}\textrm {on the lhs of the ODE and the rest on the rhs of the ODE}\hspace {3pt} \\ {} & {} & y^{\prime }+\frac {y}{x}=\sin \left (x \right ) \\ \bullet & {} & \textrm {The ODE is linear; multiply by an integrating factor}\hspace {3pt} \mu \left (x \right ) \\ {} & {} & \mu \left (x \right ) \left (y^{\prime }+\frac {y}{x}\right )=\mu \left (x \right ) \sin \left (x \right ) \\ \bullet & {} & \textrm {Assume the lhs of the ODE is the total derivative}\hspace {3pt} \frac {d}{d x}\left (y \mu \left (x \right )\right ) \\ {} & {} & \mu \left (x \right ) \left (y^{\prime }+\frac {y}{x}\right )=y^{\prime } \mu \left (x \right )+y \mu ^{\prime }\left (x \right ) \\ \bullet & {} & \textrm {Isolate}\hspace {3pt} \mu ^{\prime }\left (x \right ) \\ {} & {} & \mu ^{\prime }\left (x \right )=\frac {\mu \left (x \right )}{x} \\ \bullet & {} & \textrm {Solve to find the integrating factor}\hspace {3pt} \\ {} & {} & \mu \left (x \right )=x \\ \bullet & {} & \textrm {Integrate both sides with respect to}\hspace {3pt} x \\ {} & {} & \int \left (\frac {d}{d x}\left (y \mu \left (x \right )\right )\right )d x =\int \mu \left (x \right ) \sin \left (x \right )d x +\mathit {C1} \\ \bullet & {} & \textrm {Evaluate the integral on the lhs}\hspace {3pt} \\ {} & {} & y \mu \left (x \right )=\int \mu \left (x \right ) \sin \left (x \right )d x +\mathit {C1} \\ \bullet & {} & \textrm {Solve for}\hspace {3pt} y \\ {} & {} & y=\frac {\int \mu \left (x \right ) \sin \left (x \right )d x +\mathit {C1}}{\mu \left (x \right )} \\ \bullet & {} & \textrm {Substitute}\hspace {3pt} \mu \left (x \right )=x \\ {} & {} & y=\frac {\int \sin \left (x \right ) x d x +\mathit {C1}}{x} \\ \bullet & {} & \textrm {Evaluate the integrals on the rhs}\hspace {3pt} \\ {} & {} & y=\frac {\sin \left (x \right )-\cos \left (x \right ) x +\mathit {C1}}{x} \end {array} \]

Maple trace
`Methods for first order ODEs: 
--- Trying classification methods --- 
trying a quadrature 
trying 1st order linear 
<- 1st order linear successful`
 
Maple dsolve solution

Solving time : 0.002 (sec)
Leaf size : 17

dsolve(diff(y(x),x)+y(x)/x = sin(x), 
       y(x),singsol=all)
 
\[ y = \frac {\sin \left (x \right )-\cos \left (x \right ) x +c_1}{x} \]
Mathematica DSolve solution

Solving time : 0.068 (sec)
Leaf size : 19

DSolve[{D[y[x],x]+y[x]/x==Sin[x],{}}, 
       y[x],x,IncludeSingularSolutions->True]
 
\[ y(x)\to \frac {\sin (x)-x \cos (x)+c_1}{x} \]