Topic 4 Linear Second Order Differential Equations
4.1 The general solution of a linear equation
Consider the linear second order differential equation y″+p(x)y′+q(x)y=f(x).y′′+p(x)y′+q(x)y=f(x). Let ypyp be a particular solution, and yhyh the general solution of the associated homogeneous equation y″+p(x)y′+q(x)y=0.y′′+p(x)y′+q(x)y=0. Then the function yh+ypyh+yp is the general solution of the non-homogeneous equation y″+p(x)y′+q(x)y=f(x)y′′+p(x)y′+q(x)y=f(x).
The function yhyh can be written as c1y1+c2y2c1y1+c2y2, where y1y1 and y2y2 are linearly independent solutions of the associated homogeneous equation. To find y1y1 and y2y2, we can use dsolve
with the option output=basis
.
Example 4.1 Find two linearly independent solutions of the equation y″+y=0.y′′+y=0.
Solution. We first run commands which provide better display.
PDETools[declare](y(x), prime=x): # Turn ON the enhanced DEdisplay feature
infolevel[dsolve] := 3: # Show more detailed information about computation
Now define the equation
ode31:=diff(y(x), x$2)+y(x)=0 # here x$n = x, x, ..., x, n copies of x
To find the independent solutions, run the following command
dsolve(ode31, y(x), output=basis)
The output is [sin(x),cos(x)][sin(x),cos(x)] which means that sinxsinx and cosxcosx are linearly independent solutions.
If the homogeneous linear equation has constant coefficients, then one can also use
DETools[constcoeffsols]
to find a list of independent solutions.
Exercise 4.1 Find two linearly independent solutions of the equation y″−y′−2y=0.y′′−y′−2y=0.
To find a particular solution of a nonlinear ODE, or a linear non-homogeneous ODE, one can use the command particularsol(ODE, dependent variable)
.
Example 4.2 Find a particular solution to the equation y″−3y′+2y=2.y′′−3y′+2y=2.
Solution. First define the equation
ode32:=diff(y(x), x, x)-3*diff(y(x), x)+2*y(x)=2
To find a particular solution, we can use
with(DETools):
particularsol(ode32, y(x));
or
DETools[particularsol](ode32, y(x))
Exercise 4.2 Find a particular solution to the equation y″−3y′+2xy=2x2−3.y′′−3y′+2xy=2x2−3.
4.2 Wronskian of Solutions
The Wronskian of two solutions y1y1 and y2y2 of a linear homogeneous second order differential equation y″+p(x)y′+q(x)y=0y′′+p(x)y′+q(x)y=0 is defined by
W(y1,y2)=y1y′2−y′1y2W(y1,y2)=y1y′2−y′1y2. In Maple, one can use the command Wronskian([y_1, y_2], independent variable, determinant=true)
or LinearAlgebra[Determinant](Wronskian([y_1, y_2], independent variable)
to find the Wronskian.
Example 4.3 The equation x2y″+3xy′−3y=0x2y′′+3xy′−3y=0 has two solutions y1=xy1=x and y2=x−3y2=x−3. Find the Wronskian and determine if the two solutions are linearly independent.
Solution. We first load the package VectorCalculus
.
with(VectorCalculus):
Now we calculate the Wronskian.
LinearAlgebra[Determinant](Wronskian([x, x^(-3)], x))
The output is −4x3.−4x3.
Because the Wronskian is not identically zero, the solutions are linearly independent.
Exercise 4.3 The equation x2y″+4xy′−4y=0x2y′′+4xy′−4y=0 has two solutions y1=xy1=x and y2=x−4y2=x−4. Find the Wronskian and determine if the two solutions are linearly independent.
4.3 Linear Equations with Constant Coefficients
When solving linear equations with constant coefficients, we need to solve equations and system of equations. That can be done by the Maple command solve({equations}, {unknowns})
. Moreover, one can add constrains by using assuming
together with solve
.
Example 4.4 Solve the initial value problem y″−2y′−3y=0,y(0)=1,y′(0)=−1.y′′−2y′−3y=0,y(0)=1,y′(0)=−1.
Solution. Since this equation is a linear second order equation with constant coefficient, the solution is determined by the roots of the characteristic equation r2−2r−3=0r2−2r−3=0. Running the following Maple command will give us the roots.
rts:=solve(r^2-2*r-3=0, r);
The roots are 3,−1.3,−1.
Since the root are real numbers, the general solution of the differential equation is
yh(x):=c1*exp(rts[1]*x)+c2*exp(rts[2]*x);
The initial conditions impose two equations for the constants c1
and c2
. We can calculate y′y′ using D(y)
and solve the constants by the following command
consts:=solve({yh(0)=1, D(yh)(0)=-1}, {c1,c2});
The output is {c1=0,c2=1}.{c1=0,c2=1}.
So the solution to the initial value problem is y(x)=e−xy(x)=e−x which can be seen by the maple commands
y(x):=subs(consts, yh(x));
y(x);
Here, we take the approach of solving the problem manually. In Maple, we can use dsolve
or constcoeffsols
to solve differential equations with constant coefficients.
Exercise 4.4 Solve the initial value problem y″+3y′+2y=0,y(0)=3,y′(0)=1.y′′+3y′+2y=0,y(0)=3,y′(0)=1.
4.4 Undetermined Coefficients
For some equations that can be written into the form ay″+by′+cy=f(x)ay′′+by′+cy=f(x), a particular solution can be found using the method of undetermined coefficients. Calculations can be made easy using Maple.
Example 4.5 Find a particular solution of y″−5y′+6y=3e2x.y′′−5y′+6y=3e2x.
Solution. Since the right hand side is an exponential function, and 2 is a root of the characteristic polynomial of the complementary equation, we expect a specific solution yp=Axe2xyp=Axe2x. We then plug it into the equation to solve for AA.
Define the differential equation and the solution function.
ode341:=diff(y(x), x, x)-5*diff(y(x), x)+6*y(x)=3*exp(2*x);
yp(x):=A*x*exp(2*x);
Plugging ypyp into the differential equation and solve for A. Since AA is a number such that the equation is true for any xx. We use the solve/identity
method. The command runs like solve(identity(equation, x), vars)
.
eqnA:=subs[eval](y(x)=yp(x), ode341);
A=solve(identity(eqnA, x), A);
The output is A=−3.A=−3.
Instead of using the solve/identity
scheme, one can also build systems of equations for the undetermined coefficients manually.
When f(x)f(x) involves a polynomial, we want to get a system of undetermined coefficients. One way is to substitute xx by some general numbers. Another way is to differentiate both sides and then plug in x=0x=0. Once we get a system of the unknowns, we can solve it by the Maple command solve({eq1, eq2, ...}, {unknown1, unknown2, ...})
.
When f(x)f(x) involves sine or cosine, surely, we can plug in some general values for xx to obtain a system. We may also substitute sinxsinx by 00 and cosx=0cosx=0 to get two equations. From those two equations, we can build a system.
Example 4.6 Find a particular solution of y″−2y′−3y=xsinx.y′′−2y′−3y=xsinx.
Solution. We expect a specific solution of the same type as the right hand side. Let’s try yp=(ax+b)cosx+(cx+d)sinxyp=(ax+b)cosx+(cx+d)sinx. We then plug it into the equation to solve for aa, bb, cc, and dd.
Define the differential equation and the solution function.
ode342:=diff(y(x), x, x)-2*diff(y(x), x)-3*y(x)=x*sin(x);
yp(x):=(a*x+b)*cos(x)+(c*x+d)*sin(x);
Plugging ypyp into the differential equation and solve for A.
eqnB:=subs[eval](y(x)=yp(x), ode342);
Now let’s deduce a system of equations for aa, bb, cc and dd.
# get an equation from coefficients of cosine
CoefCosine := subs([sin(x) = 0, cos(x) = 1], eqnB);
# get an equation from coefficients of sine
CoefSine := subs([sin(x) = 1, cos(x) = 0], eqnB);
# Get four equations for a, b, c, and d
eq1 := subs(x = 0, CoefCosine):
eq2 := subs(x = 0, CoefSine):
eq3 := diff(CoefCosine, x):
eq4 := diff(CoefSine, x):
Now we solve the equations as a system.
abcd:=solve({eq1, eq2, eq3, eq4},{a, b, c, d});
The output is {a=110,b=−750,c=−15,d=−150}.{a=110,b=−750,c=−15,d=−150}.
Let’s verify that the solution.
Sol:=subs(abcd, yp(x)) # plug a, b, c, d in yp(x)
odetest(Sol, ode342)
If f(x)f(x) is a polynomial, one can also use the command polysol
to find a polynomial solution.
Exercise 4.5 Find a particular solution of y″−5y′−6y=2e3x.y′′−5y′−6y=2e3x.
4.5 Reduction of Order
Given a solution y1y1 of a linear second order differential equation y″+p(x)y′+q(x)y=f(x)y′′+p(x)y′+q(x)y=f(x), one can use the trick of variation of parameter to find another solution in the form y2=y1vy2=y1v, here vv satisfies a second order equation in the form y1v″+v′(p(x)y1+2y1)=0y1v′′+v′(p(x)y1+2y1)=0. This equation can be solve by reduction of order using the substitution u=v′u=v′. Indeed, we can expect y2=y1∫u(x)dxy2=y1∫u(x)dx.
In Maple, one can use the command reduce_order(ode, y(x)=y_1(x), u(t))
to obtain a lower order equation for uu. This command again belongs to the package DETools
.
Example 4.7 The equation x2y″+4xy′−4y=0x2y′′+4xy′−4y=0 has a solution y1=xy1=x. Find another linearly independent solution y2y2.
Solution. Let’s load packages first. Since with
can only load one package each time, let’s use a for
loop to load packages. To make the display looks better, let’s also run the declare
command.
for i in [DETools, LinearAlgebra, PDETools] do with(i) end do:
declare(y(x), prime=x):
Define the equation
ode35:=x^2*diff(y(x), x, x)+4*x*diff(y(x),x)-4*y=0;
Find the equation that u
satisfies.
RdOrder:=reduce_order(ode35, y(x) = x, u(t));
The output is y=(t(∫u(t)dt+_C1))where[{t(ut)+6u(t)=0},{t=x,u(t)=x(y′)−yx2},{x=t,y=t(∫u(t)dt+_C1)}]
You can see that the equation for u is t(ut)+6u(t)=0, where ut is v′(t).
We can solve for u and then find v. Here, we use the operand extract command op
to get the differential equation for u. The equation is the first element in the first list of the second vector of the right hand side of the output. We now get the equation for u(x).
odeu:=subs(t=x, op([2, 1, 1], rhs(RdOrder)));
Now we substitute t by x and solve for u and v.
ux:=dsolve(odeu, u(x));
v:=int(ux, x);
Therefore, by the following command, we know that y2(x)=cx4.
y[2](x):=x*v(x);
Testing y2 using the following command shows that it is a solution.
odetest(y(x)=y[2](x), ode35);
To get the second solution y2 after obtained the differential equation for u, one can also use the command
buildsol(Reduced_Order_Equation, Particular_Solution_of_u)
One can also find y2 without using
DETools
(see for example the Maple document on Linear Equations created by Prof. Douglas B. Meade.)
Exercise 4.6 The equation x2y″+3xy′−3y=0 has a solution y1=x. Find another linearly independent solution y2.
4.6 Variation of Parameters
Maple has the command varparam(Solutions, f(x), x)
to find the general solution of a linear ODE by the method of variation of parameters, where f(x) is the right-hand side function. Again this command belongs to DETools
.
Example 4.8 Find the generals solution for the equation x2y″+4xy′−4y=x using the solutions y1=x and y2=1x4 of the complementary equation x2y″+4xy′−4y=0.
Solution. We can find the general solution using one line of command.
DETools[varparam]([x, 1/x^4], x, x)
The output is _C1x+_C2x3+x314
Exercise 4.7 Find the generals solution for the equation x2y″+3xy′−3y=x using the solutions y1=x and y2=1x3 of the complementary equation x2y″+3xy′−3y=0.