2.3.6 Problem 6

Solved as second order linear constant coeff ode
Solved as second order ode using Kovacic algorithm
Solved as second order ode adjoint method
Maple
Mathematica
Sympy

Internal problem ID [8864]
Book : Own collection of miscellaneous problems
Section : section 3.0
Problem number : 6
Date solved : Wednesday, March 05, 2025 at 06:57:01 AM
CAS classification : [[_2nd_order, _linear, _nonhomogeneous]]

Solve

y+y=sin(x)

With initial conditions

y(1)=0

Solved as second order linear constant coeff ode

Time used: 0.250 (sec)

This is second order non-homogeneous ODE. In standard form the ODE is

Ay(x)+By(x)+Cy(x)=f(x)

Where A=1,B=0,C=1,f(x)=sin(x). Let the solution be

y=yh+yp

Where yh is the solution to the homogeneous ODE Ay(x)+By(x)+Cy(x)=0, and yp is a particular solution to the non-homogeneous ODE Ay(x)+By(x)+Cy(x)=f(x). yh is the solution to

y+y=0

This is second order with constant coefficients homogeneous ODE. In standard form the ODE is

Ay(x)+By(x)+Cy(x)=0

Where in the above A=1,B=0,C=1. Let the solution be y=eλx. Substituting this into the ODE gives

(1)λ2exλ+exλ=0

Since exponential function is never zero, then dividing Eq(2) throughout by eλx gives

(2)λ2+1=0

Equation (2) is the characteristic equation of the ODE. Its roots determine the general solution form.Using the quadratic formula

λ1,2=B2A±12AB24AC

Substituting A=1,B=0,C=1 into the above gives

λ1,2=0(2)(1)±1(2)(1)02(4)(1)(1)=±i

Hence

λ1=+iλ2=i

Which simplifies to

λ1=iλ2=i

Since roots are complex conjugate of each others, then let the roots be

λ1,2=α±iβ

Where α=0 and β=1. Therefore the final solution, when using Euler relation, can be written as

y=eαx(c1cos(βx)+c2sin(βx))

Which becomes

y=e0(c1cos(x)+c2sin(x))

Or

y=c1cos(x)+c2sin(x)

Therefore the homogeneous solution yh is

yh=c1cos(x)+c2sin(x)

The particular solution is now found using the method of undetermined coefficients. Looking at the RHS of the ode, which is

sin(x)

Shows that the corresponding undetermined set of the basis functions (UC_set) for the trial solution is

[{cos(x),sin(x)}]

While the set of the basis functions for the homogeneous solution found earlier is

{cos(x),sin(x)}

Since cos(x) is duplicated in the UC_set, then this basis is multiplied by extra x. The UC_set becomes

[{xcos(x),xsin(x)}]

Since there was duplication between the basis functions in the UC_set and the basis functions of the homogeneous solution, the trial solution is a linear combination of all the basis function in the above updated UC_set.

yp=A1xcos(x)+A2xsin(x)

The unknowns {A1,A2} are found by substituting the above trial solution yp into the ODE and comparing coefficients. Substituting the trial solution into the ODE and simplifying gives

2A1sin(x)+2A2cos(x)=sin(x)

Solving for the unknowns by comparing coefficients results in

[A1=12,A2=0]

Substituting the above back in the above trial solution yp, gives the particular solution

yp=xcos(x)2

Therefore the general solution is

y=yh+yp=(c1cos(x)+c2sin(x))+(xcos(x)2)

Will add steps showing solving for IC soon.

Summary of solutions found

y=(c2tan(1)+12)cos(x)+c2sin(x)xcos(x)2
Figure 2.185: Slope field y+y=sin(x)
Solved as second order ode using Kovacic algorithm

Time used: 0.185 (sec)

Writing the ode as

(1)y+y=0(2)Ay+By+Cy=0

Comparing (1) and (2) shows that

A=1(3)B=0C=1

Applying the Liouville transformation on the dependent variable gives

z(x)=yeB2Adx

Then (2) becomes

(4)z(x)=rz(x)

Where r is given by

(5)r=st=2AB2BA+B24AC4A2

Substituting the values of A,B,C from (3) in the above and simplifying gives

(6)r=11

Comparing the above to (5) shows that

s=1t=1

Therefore eq. (4) becomes

(7)z(x)=z(x)

Equation (7) is now solved. After finding z(x) then y is found using the inverse transformation

y=z(x)eB2Adx

The first step is to determine the case of Kovacic algorithm this ode belongs to. There are 3 cases depending on the order of poles of r and the order of r at . The following table summarizes these cases.

Case

Allowed pole order for r

Allowed value for O()

1

{0,1,2,4,6,8,}

{,6,4,2,0,2,3,4,5,6,}

2

Need to have at least one pole that is either order 2 or odd order greater than 2. Any other pole order is allowed as long as the above condition is satisfied. Hence the following set of pole orders are all allowed. {1,2},{1,3},{2},{3},{3,4},{1,2,5}.

no condition

3

{1,2}

{2,3,4,5,6,7,}

Table 2.41: Necessary conditions for each Kovacic case

The order of r at is the degree of t minus the degree of s. Therefore

O()=deg(t)deg(s)=00=0

There are no poles in r. Therefore the set of poles Γ is empty. Since there is no odd order pole larger than 2 and the order at is 0 then the necessary conditions for case one are met. Therefore

L=[1]

Since r=1 is not a function of x, then there is no need run Kovacic algorithm to obtain a solution for transformed ode z=rz as one solution is

z1(x)=cos(x)

Using the above, the solution for the original ode can now be found. The first solution to the original ode in y is found from

y1=z1e12BAdx

Since B=0 then the above reduces to

y1=z1=cos(x)

Which simplifies to

y1=cos(x)

The second solution y2 to the original ode is found using reduction of order

y2=y1eBAdxy12dx

Since B=0 then the above becomes

y2=y11y12dx=cos(x)1cos(x)2dx=cos(x)(tan(x))

Therefore the solution is

y=c1y1+c2y2=c1(cos(x))+c2(cos(x)(tan(x)))

This is second order nonhomogeneous ODE. Let the solution be

y=yh+yp

Where yh is the solution to the homogeneous ODE Ay(x)+By(x)+Cy(x)=0, and yp is a particular solution to the nonhomogeneous ODE Ay(x)+By(x)+Cy(x)=f(x). yh is the solution to

y+y=0

The homogeneous solution is found using the Kovacic algorithm which results in

yh=c1cos(x)+c2sin(x)

The particular solution is now found using the method of undetermined coefficients. Looking at the RHS of the ode, which is

sin(x)

Shows that the corresponding undetermined set of the basis functions (UC_set) for the trial solution is

[{cos(x),sin(x)}]

While the set of the basis functions for the homogeneous solution found earlier is

{cos(x),sin(x)}

Since cos(x) is duplicated in the UC_set, then this basis is multiplied by extra x. The UC_set becomes

[{xcos(x),xsin(x)}]

Since there was duplication between the basis functions in the UC_set and the basis functions of the homogeneous solution, the trial solution is a linear combination of all the basis function in the above updated UC_set.

yp=A1xcos(x)+A2xsin(x)

The unknowns {A1,A2} are found by substituting the above trial solution yp into the ODE and comparing coefficients. Substituting the trial solution into the ODE and simplifying gives

2A1sin(x)+2A2cos(x)=sin(x)

Solving for the unknowns by comparing coefficients results in

[A1=12,A2=0]

Substituting the above back in the above trial solution yp, gives the particular solution

yp=xcos(x)2

Therefore the general solution is

y=yh+yp=(c1cos(x)+c2sin(x))+(xcos(x)2)

Will add steps showing solving for IC soon.

Summary of solutions found

y=(c2tan(1)+12)cos(x)+c2sin(x)xcos(x)2
Figure 2.186: Slope field y+y=sin(x)
Solved as second order ode adjoint method

Time used: 1.908 (sec)

In normal form the ode

(1)y+y=sin(x)

Becomes

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

Where

p(x)=0q(x)=1r(x)=sin(x)

The Lagrange adjoint ode is given by

ξ(ξp)+ξq=0ξ(0)+(ξ(x))=0ξ(x)+ξ(x)=0

Which is solved for ξ(x). This is second order with constant coefficients homogeneous ODE. In standard form the ODE is

Aξ(x)+Bξ(x)+Cξ(x)=0

Where in the above A=1,B=0,C=1. Let the solution be ξ=eλx. Substituting this into the ODE gives

(1)λ2exλ+exλ=0

Since exponential function is never zero, then dividing Eq(2) throughout by eλx gives

(2)λ2+1=0

Equation (2) is the characteristic equation of the ODE. Its roots determine the general solution form.Using the quadratic formula

λ1,2=B2A±12AB24AC

Substituting A=1,B=0,C=1 into the above gives

λ1,2=0(2)(1)±1(2)(1)02(4)(1)(1)=±i

Hence

λ1=+iλ2=i

Which simplifies to

λ1=iλ2=i

Since roots are complex conjugate of each others, then let the roots be

λ1,2=α±iβ

Where α=0 and β=1. Therefore the final solution, when using Euler relation, can be written as

ξ=eαx(c1cos(βx)+c2sin(βx))

Which becomes

ξ=e0(c1cos(x)+c2sin(x))

Or

ξ=c1cos(x)+c2sin(x)

Will add steps showing solving for IC soon.

The original ode now reduces to first order ode

ξ(x)yyξ(x)+ξ(x)p(x)y=ξ(x)r(x)dxy+y(p(x)ξ(x)ξ(x))=ξ(x)r(x)dxξ(x)

Or

yy(c1sin(x)+c2cos(x))c1cos(x)+c2sin(x)=cos(x)2c12+c2(cos(x)sin(x)2+x2)c1cos(x)+c2sin(x)

Which is now a first order ode. This is now solved for y. 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)=c1sin(x)+c2cos(x)c1cos(x)+c2sin(x)p(x)=c2cos(x)sin(x)cos(x)2c1+c2x2c2sin(x)+2c1cos(x)

The integrating factor μ is

μ=eqdx=ec1sin(x)+c2cos(x)c1cos(x)+c2sin(x)dx=1c1cos(x)+c2sin(x)

The ode becomes

ddx(μy)=μpddx(μy)=(μ)(c2cos(x)sin(x)cos(x)2c1+c2x2c2sin(x)+2c1cos(x))ddx(yc1cos(x)+c2sin(x))=(1c1cos(x)+c2sin(x))(c2cos(x)sin(x)cos(x)2c1+c2x2c2sin(x)+2c1cos(x))d(yc1cos(x)+c2sin(x))=(c2cos(x)sin(x)cos(x)2c1+c2x(c1cos(x)+c2sin(x))(2c2sin(x)+2c1cos(x)))dx

Integrating gives

yc1cos(x)+c2sin(x)=c2cos(x)sin(x)cos(x)2c1+c2x(c1cos(x)+c2sin(x))(2c2sin(x)+2c1cos(x))dx=cos(x)x2c2sin(x)+2c1cos(x)+c3

Dividing throughout by the integrating factor 1c1cos(x)+c2sin(x) gives the final solution

y=(2c1c3x)cos(x)2+sin(x)c2c3

Hence, the solution found using Lagrange adjoint equation method is

y=(2c1c3x)cos(x)2+sin(x)c2c3

The constants can be merged to give

y=(2c1x)cos(x)2+c2sin(x)

Will add steps showing solving for IC soon.

Summary of solutions found

y=(2c2tan(1)+1x)cos(x)2+c2sin(x)
Figure 2.187: Slope field y+y=sin(x)
Maple. Time used: 0.072 (sec). Leaf size: 31
ode:=diff(diff(y(x),x),x)+y(x) = sin(x); 
ic:=y(1) = 0; 
dsolve([ode,ic],y(x), singsol=all);
 
y=((2c21)tan(1)x+1)cos(x)2+sin(x)(2c2+1)2

Maple trace

`Methods for second order ODEs: 
--- Trying classification methods --- 
trying a quadrature 
trying high order exact linear fully integrable 
trying differential order: 2; linear nonhomogeneous with symmetry [0,1] 
trying a double symmetry of the form [xi=0, eta=F(x)] 
-> Try solving first the homogeneous part of the ODE 
   checking if the LODE has constant coefficients 
   <- constant coefficients successful 
<- solving first the homogeneous part of the ODE successful`
 

Maple step by step

Let’s solve[d2dx2y(x)+y(x)=sin(x),y(1)=0]Highest derivative means the order of the ODE is2d2dx2y(x)Characteristic polynomial of homogeneous ODEr2+1=0Use quadratic formula to solve forrr=0±(4)2Roots of the characteristic polynomialr=(I,I)1st solution of the homogeneous ODEy1(x)=cos(x)2nd solution of the homogeneous ODEy2(x)=sin(x)General solution of the ODEy(x)=C1y1(x)+C2y2(x)+yp(x)Substitute in solutions of the homogeneous ODEy(x)=C1cos(x)+C2sin(x)+yp(x)Find a particular solutionyp(x)of the ODEUse variation of parameters to findypheref(x)is the forcing function[yp(x)=y1(x)(y2(x)f(x)W(y1(x),y2(x))dx)+y2(x)(y1(x)f(x)W(y1(x),y2(x))dx),f(x)=sin(x)]Wronskian of solutions of the homogeneous equationW(y1(x),y2(x))=[cos(x)sin(x)sin(x)cos(x)]Compute WronskianW(y1(x),y2(x))=1Substitute functions into equation foryp(x)yp(x)=cos(x)(sin(x)2dx)+sin(x)(sin(2x)dx)2Compute integralsyp(x)=sin(x)4xcos(x)2Substitute particular solution into general solution to ODEy(x)=C1cos(x)+C2sin(x)+sin(x)4xcos(x)2
Mathematica. Time used: 0.023 (sec). Leaf size: 18
ode=D[y[x],{x,2}]+y[x]==Sin[x]; 
ic={y[0] == 0}; 
DSolve[{ode,ic},y[x],x,IncludeSingularSolutions->True]
 
y(x)12xcos(x)+c2sin(x)
Sympy. Time used: 0.103 (sec). Leaf size: 26
from sympy import * 
x = symbols("x") 
y = Function("y") 
ode = Eq(y(x) - sin(x) + Derivative(y(x), (x, 2)),0) 
ics = {y(1): 0} 
dsolve(ode,func=y(x),ics=ics)
 
y(x)=C2sin(x)+(C2sin(1)cos(1)x2+12)cos(x)