2.2.39 Problem 39

Solved using first_order_ode_linear
Solved using first_order_ode_exact
Maple
Mathematica
Sympy

Internal problem ID [9162]
Book : Second order enumerated odes
Section : section 2
Problem number : 39
Date solved : Sunday, March 30, 2025 at 02:24:27 PM
CAS classification : [_linear]

Solved using first_order_ode_linear

Time used: 0.057 (sec)

Solve

y+ycot(x)=2cos(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)=cot(x)p(x)=2cos(x)

The integrating factor μ is

μ=eqdx=ecot(x)dx=sin(x)

The ode becomes

ddx(μy)=μpddx(μy)=(μ)(2cos(x))ddx(ysin(x))=(sin(x))(2cos(x))d(ysin(x))=(2sin(x)cos(x))dx

Integrating gives

ysin(x)=2sin(x)cos(x)dx=sin(x)2+c1

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

y=sin(x)+c1csc(x)
Figure 2.123: Slope field y+ycot(x)=2cos(x)

Summary of solutions found

y=sin(x)+c1csc(x)
Solved using first_order_ode_exact

Time used: 0.125 (sec)

Solve

y+ycot(x)=2cos(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

dy=(ycot(x)+2cos(x))dx(2A)(ycot(x)2cos(x))dx+dy=0

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

M(x,y)=ycot(x)2cos(x)N(x,y)=1

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(ycot(x)2cos(x))=cot(x)

And

Nx=x(1)=0

Since MyNx, then the ODE is not exact. Since the ODE is not exact, we will try to find an integrating factor to make it exact. Let

A=1N(MyNx)=1((cot(x))(0))=cot(x)

Since A does not depend on y, then it can be used to find an integrating factor. The integrating factor μ is

μ=eAdx=ecot(x)dx

The result of integrating gives

μ=eln(sin(x))=sin(x)

M and N are multiplied by this integrating factor, giving new M and new N which are called M and N for now so not to confuse them with the original M and N.

M=μM=sin(x)(ycot(x)2cos(x))=cos(x)(2sin(x)+y)

And

N=μN=sin(x)(1)=sin(x)

Now a modified ODE is ontained from the original ODE, which is exact and can be solved. The modified ODE is

M+Ndydx=0(cos(x)(2sin(x)+y))+(sin(x))dydx=0

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=sin(x)dy(3)ϕ=ysin(x)+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=cos(x)y+f(x)

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

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

Solving equation (5) for f(x) gives

f(x)=2sin(x)cos(x)

Integrating the above w.r.t x gives

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

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

ϕ=ysin(x)+cos(2x)2+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=ysin(x)+cos(2x)2

Solving for y gives

y=cos(2x)2c22sin(x)

Which simplifies to

y=(cos(x)2+c2+12)csc(x)
Figure 2.124: Slope field y+ycot(x)=2cos(x)

Summary of solutions found

y=(cos(x)2+c2+12)csc(x)
Maple. Time used: 0.002 (sec). Leaf size: 16
ode:=diff(y(x),x)+cot(x)*y(x) = 2*cos(x); 
dsolve(ode,y(x), singsol=all);
 
y=(cos(x)2+c1+12)csc(x)

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)cot(x)=2cos(x)Highest derivative means the order of the ODE is1ddxy(x)Solve for the highest derivativeddxy(x)=y(x)cot(x)+2cos(x)Group terms withy(x)on the lhs of the ODE and the rest on the rhs of the ODEddxy(x)+y(x)cot(x)=2cos(x)The ODE is linear; multiply by an integrating factorμ(x)μ(x)(ddxy(x)+y(x)cot(x))=2μ(x)cos(x)Assume the lhs of the ODE is the total derivativeddx(y(x)μ(x))μ(x)(ddxy(x)+y(x)cot(x))=(ddxy(x))μ(x)+y(x)(ddxμ(x))Isolateddxμ(x)ddxμ(x)=μ(x)cot(x)Solve to find the integrating factorμ(x)=sin(x)Integrate both sides with respect tox(ddx(y(x)μ(x)))dx=2μ(x)cos(x)dx+C1Evaluate the integral on the lhsy(x)μ(x)=2μ(x)cos(x)dx+C1Solve fory(x)y(x)=2μ(x)cos(x)dx+C1μ(x)Substituteμ(x)=sin(x)y(x)=2sin(x)cos(x)dx+C1sin(x)Evaluate the integrals on the rhsy(x)=sin(x)2+C1sin(x)Simplifyy(x)=sin(x)+C1csc(x)
Mathematica. Time used: 0.04 (sec). Leaf size: 23
ode=D[y[x],x]+y[x]*Cot[x]==2*Cos[x]; 
ic={}; 
DSolve[{ode,ic},y[x],x,IncludeSingularSolutions->True]
 
y(x)csc(x)(1xsin(2K[1])dK[1]+c1)
Sympy. Time used: 0.990 (sec). Leaf size: 12
from sympy import * 
x = symbols("x") 
y = Function("y") 
ode = Eq(y(x)/tan(x) - 2*cos(x) + Derivative(y(x), x),0) 
ics = {} 
dsolve(ode,func=y(x),ics=ics)
 
y(x)=C1cos2(x)sin(x)