2.4.2 Problem 2

Solved using first_order_ode_linear
Solved using first_order_ode_exact
Maple
Mathematica
Sympy

Internal problem ID [18475]
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 : Saturday, April 26, 2025 at 11:22:08 AM
CAS classification : [_linear]

Solved using first_order_ode_linear

Time used: 0.088 (sec)

Solve

y+yx=sin(x)

In canonical form a linear first order is

y+q(x)y=p(x)

Comparing the above to the given ode shows that

q(x)=1xp(x)=sin(x)

The integrating factor μ is

μ=eqdx=e1xdx=x

The ode becomes

ddx(μy)=μpddx(μy)=(μ)(sin(x))ddx(yx)=(x)(sin(x))d(yx)=(sin(x)x)dx

Integrating gives

yx=sin(x)xdx=sin(x)cos(x)x+c1

Dividing throughout by the integrating factor x gives the final solution

y=sin(x)cos(x)x+c1x
Figure 2.42: Slope field y+yx=sin(x)

Summary of solutions found

y=sin(x)cos(x)x+c1x
Solved using first_order_ode_exact

Time used: 0.141 (sec)

Solve

y+yx=sin(x)

To solve an ode of the form

(A)M(x,y)+N(x,y)dydx=0

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

ddxϕ(x,y)=0

Hence

(B)ϕx+ϕydydx=0

Comparing (A,B) shows that

ϕx=Mϕy=N

But since 2ϕxy=2ϕyx then for the above to be valid, we require that

My=Nx

If the above condition is satisfied, then the original ode is called exact. We still need to determine ϕ(x,y) but at least we know now that we can do that since the condition 2ϕxy=2ϕyx 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

(1A)M(x,y)dx+N(x,y)dy=0

Therefore

(x)dy=(sin(x)xy)dx(2A)(sin(x)x+y)dx+(x)dy=0

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

M(x,y)=sin(x)x+yN(x,y)=x

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

My=Nx

Using result found above gives

My=y(sin(x)x+y)=1

And

Nx=x(x)=1

Since My=Nx, then the ODE is exact The following equations are now set up to solve for the function ϕ(x,y)

(1)ϕx=M(2)ϕy=N

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

ϕydy=Ndyϕydy=xdy(3)ϕ=yx+f(x)

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

(4)ϕx=y+f(x)

But equation (1) says that ϕx=sin(x)x+y. Therefore equation (4) becomes

(5)sin(x)x+y=y+f(x)

Solving equation (5) for f(x) gives

f(x)=sin(x)x

Integrating the above w.r.t x gives

f(x)dx=(sin(x)x)dxf(x)=cos(x)xsin(x)+c2

Where c2 is constant of integration. Substituting result found above for f(x) into equation (3) gives ϕ

ϕ=yx+cos(x)xsin(x)+c2

But since ϕ itself is a constant function, then let ϕ=c3 where c3 is new constant and combining c2 and c3 constants into the constant c2 gives the solution as

c2=yx+cos(x)xsin(x)

Solving for y gives

y=cos(x)xsin(x)c2x

Which simplifies to

y=cos(x)x+sin(x)+c2x
Figure 2.43: Slope field y+yx=sin(x)

Summary of solutions found

y=cos(x)x+sin(x)+c2x
Maple. Time used: 0.001 (sec). Leaf size: 17
ode:=diff(y(x),x)+y(x)/x = sin(x); 
dsolve(ode,y(x), singsol=all);
 
y=sin(x)cos(x)x+c1x

Maple trace

Methods for first order ODEs: 
--- Trying classification methods --- 
trying a quadrature 
trying 1st order linear 
<- 1st order linear successful
 

Maple step by step

Let’s solveddxy(x)+y(x)x=sin(x)Highest derivative means the order of the ODE is1ddxy(x)Solve for the highest derivativeddxy(x)=y(x)x+sin(x)Group terms withy(x)on the lhs of the ODE and the rest on the rhs of the ODEddxy(x)+y(x)x=sin(x)The ODE is linear; multiply by an integrating factorμ(x)μ(x)(ddxy(x)+y(x)x)=μ(x)sin(x)Assume the lhs of the ODE is the total derivativeddx(y(x)μ(x))μ(x)(ddxy(x)+y(x)x)=(ddxy(x))μ(x)+y(x)(ddxμ(x))Isolateddxμ(x)ddxμ(x)=μ(x)xSolve to find the integrating factorμ(x)=xIntegrate both sides with respect tox(ddx(y(x)μ(x)))dx=μ(x)sin(x)dx+C1Evaluate the integral on the lhsy(x)μ(x)=μ(x)sin(x)dx+C1Solve fory(x)y(x)=μ(x)sin(x)dx+C1μ(x)Substituteμ(x)=xy(x)=xsin(x)dx+C1xEvaluate the integrals on the rhsy(x)=sin(x)xcos(x)+C1x
Mathematica. Time used: 0.03 (sec). Leaf size: 19
ode=D[y[x],x]+y[x]/x==Sin[x]; 
ic={}; 
DSolve[{ode,ic},y[x],x,IncludeSingularSolutions->True]
 
y(x)sin(x)xcos(x)+c1x
Sympy. Time used: 0.242 (sec). Leaf size: 14
from sympy import * 
x = symbols("x") 
y = Function("y") 
ode = Eq(-sin(x) + Derivative(y(x), x) + y(x)/x,0) 
ics = {} 
dsolve(ode,func=y(x),ics=ics)
 
y(x)=C1xcos(x)+sin(x)x