Ordinary Di Erential Equations: 3.1 Introduction and Simple Examples
Ordinary Di Erential Equations: 3.1 Introduction and Simple Examples
Ordinary Di Erential Equations: 3.1 Introduction and Simple Examples
dy 1 1
l.h.s = + 2xy 2 = · 2x + 2x · 2 = 0 = r.h.s.
dx (x2 + c) 2 (x + c)2
Note that “l.h.s.” and “r.h.s.” stand for left- and right-hand side, respectively. Di↵erential
equations occur everywhere in physics. Examples include:
51
According to Newton’s law of motion: Force = mass ⇥ acceleration = m dv/dt =
m d2 x/dt2 , so that
d2 x
m 2 = kx. (3.2)
dt
• Newton’s law of cooling:
This law states that the rate at which a hot body cools is proportional to the di↵erence
T TS between the temperature T of the body and the temperature TS of the
surroundings. Expressed as an equation, this says:
dT /dt = ↵ (T TS ) , (3.3)
~2 d 2
+ V (x) (x) = E (x). (3.4)
2m dx2
• Wave equation: in vacuum, the change of the electric field E(x, t) as a function of
position x and time t is described by the wave equation
@ 2E 2
2@ E
= c . (3.5)
@t2 @x2
Figure 3.3: An electromagnetic wave propagating with velocity c. It is easy to check that
E(x, t) = f (x ct) with f an arbitrary function is a solution of the wave equation.
52
These are all di↵erential equations, because they contain derivatives d2 x/dt2 , dT /dt,
d2 /dx2 , @ 2 E/@t2 , and @ 2 E/@x2 . We write down a di↵erential equation (usually based
upon some assumptions about a physics system) and then try to find the functions that
satisfy the equation. In physics, once we have such a function, we can use it to predict
other behaviours of the system. The aim of this and the next few lectures is to explain
how to find solutions of di↵erential equations.
3.1.1 Terminology
We need to define some terminology that will often be used:
• Independent and dependent variables: For the harmonic oscillator, the displacement
x(t) depends on time t, so we call t the independent variable and x the dependent
variable. The idea is to find the function x(t) expressing how the dependent variable
depends on the independent variable. Similarly, for the cooling body, time t is the
independent variable and T is the dependent variable. For the wave equation the
electric field E(x, t) is the dependent variable, x and t are independent variables.
• Ordinary di↵erential equations (ODE’s): these are equations with only one indepen-
dent variable, so that we only have ordinary di↵erentials (e.g. d2 x/dt2 ), not partial
di↵erentials. Examples (3.1), (3.2), (3.3), and (3.4) are all ODE’s. The wave equation
(3.5) is a partial di↵erential equation. In this course we will only discuss ODE’s.
• Order of di↵erential equation: this refers to the maximum number of times that the
dependent variable is di↵erentiated in the equation. In examples (3.1) and (3.3)
we only have first derivatives, so these are first-order di↵erential equations. The
harmonic oscillator (3.2) is an example of a second-order di↵erential equation since
x(t) is di↵erentiated twice (d2 x/dt2 ).
dn y dn 1 y d2 y dy
an (x) n
+ a n 1 (x) n 1
+ . . . + a 2 (x) 2
+ a1 (x) + a0 (x)y = b(x), (3.6)
dx dx dx dx
where ai (x) and b(x) are functions of x (could also be constant) and an (x) 6= 0.
53
• Homogeneity: a linear ODE is homogeneous if the dependent variable appears to
the first power in every term. For example, the harmonic oscillator ODE (3.2) is
homogeneous, because every term contains x(t).
• Notation: in physics, the dependent and independent variables are often given symbols
which reflect the physical meaning of the variables (e.g. T for temperature, t for
time). But in these lectures, we will usually call the dependent variable y and the
independent variable x (as in (3.1)).
since d✓/dt = e ↵t · ( ↵) = ↵✓. However, it is not the only possible solution. A more
general solution is
↵t
✓(t) = Ae . (3.8)
The arbitrary constant A 2 R multiplies the whole solution because the original ODE is
homogeneous.
• For a linear homogeneous ODE, if we have found a solution y0 (x) then the
function y(x) = Ay0 (x), where A 2 R is an arbitrary constant, is also a solution.
Proof of 2nd statement: We consider a general homogeneous linear ODE, Eq. (3.6) with
b(x) ⌘ 0. Let y0 (x) be a solution of this ODE,
d n y0 dy0
an (x) n
+ . . . + a1 (x) + a0 (x)y0 = 0. (⇤)
dx dx
54
We now show that y(x) = Ay0 (x) also satisfies the ODE,
dn y dy
an (x) n
+ . . . + a1 (x) + a0 (x)y
dx dx
y(x)=Ay0 (x) d n y0 dy0
= an (x)A n + . . . + a1 (x)A + a0 (x)Ay0
✓ dx dx ◆
d n y0 dy0
= A an (x) n + . . . + a1 (x) + a0 (x)y0
dx dx
(⇤)
= A · 0 = 0.
General rule: Take the original ODE, splitting dy/dx into dy and dx. If we can rear-
range the equation so that dy and all other quantities containing y are on the left and
dx and all quantities containing x are on the right, then the ODE is called separable.
In this case the general solution can be found by integrating the separated equa-
tion. Note that the integrals are indefinite. This is where the arbitrary integration
constant enters.
Warning: One cannot always just pick apart a di↵erential like this. In general it might help
to remember that it is a limit, and that the dy and dx belong together. If the operation
makes sense when you move away from the limit and then move back, its usually ok. If we
were mathematicians, we’d have to prove this formally, of course.
56
3.2.1 Worked Examples
(1) Find the general solution y = f (x) of the di↵erential equation
dy
= y sin x.
dx
57
(2) Find the solution of the separable ODE
dy
x xy = y,
dx
for which y = 1 when x = 2.
58
(3) The two above examples were homogeneous, linear ODE’s, giving rise to a multi-
plicative integration constant. Let’s now solve the non-linear first-order ODE
dy
xy 2 = x.
dx
59
3.3 Linear First-Order ODE’s
Previously, I explained how to solve first-order ODE’s in the case where they are separable.
Unfortunately, most first-order ODE’s are not separable. However, many of them can still
be solved. The aim of this section is to explain a completely general method for solving
linear first-order ODE’s. According to Eq. (3.6), the most general form of such an ODE is
dy
a1 (x) + a0 (x)y = b(x).
dx
Dividing by a1 (x) we can bring this to the “standard form” of a linear first-order ODE:
dy
+ P (x)y = Q(x). (3.14)
dx
P (x) and Q(x) can be complicated functions of x. Note that this linear ODE is inho-
mogeneous unless Q(x) ⌘ 0.
60
with B 2 R. Exponentiating both sides we obtain
R
P (x)dx
S(x) = e . (3.18)
Note that we have fixed the integration constant since we just need a special solution of
(3.16). Combining Eqs. (3.17) and (3.18), we have found the general solution of the linear
first-order ODE (3.14),
✓Z ◆ R
1 P (x)dx
y= S(x)Q(x)dx + C , where S(x) = e . (3.19)
S(x)
Rather than memorising the formal solution it is better just to remember the basic idea.
Let’s look at the example
dy 1
+ y = 1. (3.20)
dx x
We multiply the ODE with the integrating factor S(x),
dy 1
S(x) + S(x) y = S(x) (⇤)
dx x
and demand that it satisfies the condition
dS 1
= S(x) .
dx x
d
In this case we can write the l.h.s. of (*) as dx
[S(x)y]. The ODE for S(x) can be easily
solved by separation of variables,
dS dx
= =) ln |S| = ln |x| + B =) S(x) = Ax (A 2 R).
S x
Note that we just need a special solution so we can set A = 1. With S(x) = x we can write
(*) as
d
(xy) = x,
dx
which after integration gives
1 1 C
xy = x2 + C =) y = x + .
2 2 x
This is the general solution of ODE (3.20).
61
3.3.2 Worked Examples
(1) Find the general solution of the linear first-order ODE
dy 1
x2 2xy = .
dx x
to standard form
We
bring the ODE
dd
Ey 3
and
multiply with an integrating factor sad
sexyday SHE y Skates
and demand dada Skc c
Our ODE then reads
dafsexly Sixx e
Obtain of variables
Sly by separation of
dsg Eda butsI 2h41
SE Te
na et da Sza 5
4
2 x C C CERI
Ck
ya t
62
(2) Find the general solution of the linear first-order ODE
dy
+ y cos x = sin(2x).
dx
Sexy esinx
r es da f estoy esh siuC2x
esh g
u
folk e siuC2xl te
sink 2fd3
e Z t C
u v
DZ cosxd x
21 Eez fore J t c
ZEE c e t C
2Lsinx 1 ester c
sin x
2 six c C e
glad
63
3.4 Perfect Di↵erential Method
If a first-order ODE is non-linear (so it contains terms like y 2 , yy 0 , . . .), the systematic
method discussed in Sec. 3.3 cannot be used. If the ODE is also non-separable, then the
only realistic hope left is the perfect-di↵erential method, also known as the exact-di↵erential
method. If the ODE contains dy/dx only to the first power, then it can always be written
as
dy
Q(x, y) + P (x, y) = 0, (3.21)
dx
or equivalently as
Here P and Q are functions of x and y. Now suppose that P (x, y) and Q(x, y) are the
partial di↵erentials with respect to x and y of some other function f (x, y),
@f @f
P (x, y) = , Q(x, y) = . (3.23)
@x @y
In this case, the l.h.s. of Eq. (3.22) can be written as the total di↵erential of f ,
@f @f
df = dx + dy = P (x, y)dx + Q(x, y)dy = 0. (3.24)
@x @y
Since df = 0, the function f has to be constant,
f (x, y) = C, (3.25)
where C 2 R is an arbitrary constant. This represents the general solution to the original
ODE (3.22). Note that Eq. (3.25) does not contain derivatives. It implicitly defines the
functions y(x) that satisfy the original ODE. However, it is not always possible to rearrange
the implicit expression (3.25) to express y as a function of x (to solve for y).
In this method, we need to test whether the given P (x, y) and Q(x, y) can be represented
as @f /@x and @f /@y. A necessary condition for this to be true is
@P @ 2f @ 2f @Q
= = = . (3.26)
@y @y@x @x@y @x
It can be shown that @P/@y = @Q/@x is also a sufficient condition for P and Q to be
representable in this way.
To see how this works in practice, say we want to find the general solution of the non-linear,
non-seperable, first-order ODE
dy
2x2 y + 2xy 2 = 1. (3.27)
dx
This ODE can be expressed in the standard form (3.22) with
64
We first need to find out if the ODE can be solved by the perfect di↵erential method.
We apply the standard test: since @P/@y = 4xy = @Q/@x, we know that there exists a
function f (x, y) such that P (x, y) = @f /@x and Q(x, y) = @f /@y,
@f @f
I. = 2xy 2 1, II. = 2x2 y.
@x @y
Integrating the first equation, we obtain
Z
f (x, y) = (2xy 2 1)dx = x2 y 2 x + g(y), (3.28)
where g(y) is the “integration constant”. Note that y is held constant in the above integra-
tion, so g can be function of y. Or to phrase this di↵erently, taking the partial derivative
with respect to x in Eq. I, any function of y is treated as a constant and drops out. Likewise,
from integration of II, we obtain
Z
f (x, y) = 2x2 y dy = x2 y 2 + h(x). (3.29)
We have to determine the functions g(y) and h(x) such that Eqs. (3.28) and (3.29) give us
the same expression for f (x, y). This is the case for h(x) = x and g(y) = 0, corresponding
to f (x, y) = x2 y 2 x. The general solution of ODE (3.26) is given by f (x, y) = const,
x2 y 2 x = C, (3.30)
with C 2 R. Contours of points (x, y) that satisfy this equation for di↵erent values of
the integration
p constant C are shown below. Note that we can solve Eq. (3.30) for y,
y = ± 1/x + C/x2 .
2
C=1
C=0
C= 1
y 0
-2
-4
-1 0 1 2 3 4 5 6
x
65
3.4.1 Worked Example
Show that the ODE ⇣ ⌘ dy
x2 x2
2xy + e y2
= 2xye
dx
can be written as an exact di↵erential and find the general solution in an implicit form.
66
3.5 Second-Order Linear ODE’s with Constant Coef-
ficients
Second-order ODE’s are those containing the second derivative d2 y/dx2 of the dependent
variable. The only kind of second-order ODE’s considered here are linear ODE’s, in which
the coefficients of d2 y/dx2 , dy/dx and y are all constant,
d2 y dy
a2 2
+ a1 + a0 y = b(x),
dx dx
where b(x) is a function of x only. We will assume that the constants a2 , a1 and a0 are real
numbers and that a2 6= 0 (otherwise the ODE would be first order). Dividing by a2 , the
ODE can always be brought to the standard form
d2 y dy
2
+ p + qy = f (x). (3.31)
dx dx
d2 y dy
2
+ p + qy = 0. (3.32)
dx dx
y = ekx , (3.33)
provided that the constant k is chosen appropriately. To see this we first calculate the
first and second derivatives of the function (3.33),
dy d2 y
= kekx , = k 2 ekx .
dx dx2
Inserting the ansatz (3.33) into the ODE (3.32) we obtain
d2 y dy
0= 2
+ p + qy = k 2 ekx + pkekx + qekx = k 2 + pk + q ekx .
dx dx
Our ansatz satisfies the ODE if the constant k is a solution of the quadratic equation
k 2 + pk + q = 0. (3.34)
67
We have found two specific solutions y1 = ek1 x and y2 = ek2 x . How to construct the
general solution of the homogeneous ODE (3.32)? In general, if two functions y1 (x) and
y2 (x) satisfy (3.32), then the linear combination y(x) = Ay1 (x) + By2 (x) is also a solution
(note that this is true for any linear homogeneous ODE):
✓ ◆
d2 y dy d 2 y1 d 2 y2 dy1 dy2
+ p + qy = A 2 + B 2 + p A +B + q (Ay1 + By2 )
dx2 dx dx dx dx dx
✓ 2 ◆ ✓ 2 ◆
d y1 dy1 d y2 dy2
= A +p + qy1 +B +p + qy2 = 0.
dx2 dx dx2 dx
| {z } | {z }
=0 =0
with k1 , k2 given in Eq. (3.35) is a solution of the homogeneous equation (3.32). This
is the general solution since it contains two integration constants A, B, as required for a
second-order ODE.
• Real roots:
p2
q>0
4
In this case k1 , k2 2 R, k1 6= k2 , and the general solution (3.36) is the sum of two
exponential functions. The function y is real if A, B 2 R.
• Complex roots:
p2
q<0
4
In this case we can write
k1,2 = ↵ ± i , (3.37)
p
with ↵ = p/2 2 R and = q p2 /4 2 R. The general solution of the homoge-
neous ODE is given by
y = Aek1 x + Bek2 x
= Ae(↵+i )x + Be(↵ i )x
= e↵x Aei x + Be i x
= e↵x [(A + B) cos( x) + i(A B) sin( x)] ,
where, in the last step, we have used Euler’s Theorem eiz = cos z + i sin z. We can
always redefine the integration constants, C := A + B and D := i(A B), yielding
68
• Degenerate roots:
p2
q=0
4
The two roots of Eq. (3.35) are identical, k1 = k2 = k = p/2. While y1 = ekx is
a solution of the ODE (3.32), y = Aekx cannot be the most general solution since
it only contains one arbitrary constant. We show that y2 = xekx is an independent
second solution,
d 2 y2 dy2 d kx
2
+p + qy2 = e + kxekx + p ekx + kxekx + qxekx
dx dx dx
= kekx + kekx + k 2 xekx + pekx + pkxekx + qxekx
⇣ p ⌘ kx
= 2 k+ e + k 2 + pk + q xekx
✓ 2 2 ◆
k= p
p
=2 + q xekx = 0.
4
| {z }
=0
Hence the general solution in the degenerate case (sometimes referred to as “marginal
case”) is
y = Aekx + Bxekx . (A, B 2 R) (3.39)
69
3.5.2 Worked Examples
Find the general solutions of the following homogeneous second-order di↵erential equations:
d2 y dy d2 y dy d2 y dy
(a) 2 2
+ 5 + 3y = 0, (b) 10 + 25y = 0, (c) + 4 + 5y = 0.
dx dx dx2 dx dx 2 dx
70
71
3.5.3 Inhomogeneous ODE’s
We now return to the original inhomogeneous ODE (3.31),
d2 y dy
2
+ p + qy = f (x).
dx dx
The first step is to obtain a general solution of the corresponding homogeneous ODE
(obtained by setting f (x) = 0), using the methods discussed in the previous section. This
solution is called the complementary function yCF (x). Let us suppose that somehow we can
find a particular solution of the inhomogeneous ODE (3.31). Such a solution is called the
particular integral yPI (x). Then the sum
y(x) = yCF (x) + yPI (x) (3.40)
is the general solution of the inhomogeneous ODE since
✓ 2 ◆ ✓ 2 ◆
d2 y dy d yCF dyCF d yPI dyPI
+ p + qy = +p + qyCF + +p + qyPI = f (x),
dx2 dx dx2 dx dx2 dx
| {z } | {z }
=0 =f (x)
and yCF (x) contains two arbitrary integration constants. This means that the whole prob-
lem is solved if we have a way of finding yPI (x). Unfortunately, this is usually down to a
matter of trial and error.
In these lectures, we will only describe how to find a particular integral yPI (x) for some
important and common types of functions f (x).
• Polynomials. If f (x) is an nth degree polynomial,
f (x) = A0 + A1 x + . . . + An xn , (3.41)
then there is always a particular integral of the form
yPI (x) = ↵0 + ↵1 x + . . . + ↵n xn . (3.42)
To determine the coefficients ↵0 , . . . , ↵n for any given p, q, A0 , . . . An we insert the
ansatz (3.41) into the inhomogeneous ODE,
A0 + A1 x + . . . + An xn = 2↵2 + 6↵3 x + . . . + ↵n n(n 1)xn 2
+p ↵1 + 2↵2 x + . . . + n↵n xn 1
+q (↵0 + ↵1 x + . . . + ↵n xn )
= (2↵2 + p↵1 + q↵0 ) + (6↵3 + 2p↵2 + q↵1 ) x
+ . . . + q↵n xn .
For the two polynomials to be equal, the coefficients have to be equal, leading to
(n + 1) coupled linear equations,
2↵2 + p↵1 + q↵0 = A0
6↵3 + 2p↵2 + q↵1 = A1
..
.
q↵n = An .
Solving this set of equations we obtain ↵0 , . . . , ↵n .
72
• Exponentials. If f (x) is an exponential function,
d2 y dy
A0 e!x = 2
+ p + qy
dx dx
= ↵0 ! e + p↵0 !e!x + q↵0 e!x
2 !x
= ↵0 ! 2 + p! + q e!x . (3.45)
To check this and to determine B, we insert the ansatz into the ODE,
d2 y dy
A0 e!x = 2
+ p + qy
dx
✓ dx
◆
d
= + p (Be!x + B!xe!x ) + qBxe!x
dx
= 2B!e!x + B! 2 xe!x + pBe!x + pB!xe!x + qBxe!x
= Be!x 2! + ! 2 x + p + p!x + qx
= Be!x [(2! + p) + (! 2 + p! + q) x].
| {z }
=0
73
with coefficients ↵0 and ↵1 expressible in terms of p, q, A0 , A1 and !. To see this,
note that
dyPI
= ↵0 ! sin(!x) + ↵1 ! cos(!x),
dx
d2 yPI
= ↵0 ! 2 cos(!x) ↵1 ! 2 sin(!x).
dx2
Inserting into the inhomogeneous ODE, we obtain
(q ! 2 )↵0 + p!↵1 = A0 ,
p!↵0 + (q ! 2 )↵1 = A1 .
These are simultaneous linear equations which can be solved to obtain ↵0 and ↵1 .
74
3.5.4 Worked Examples
Find the solutions of the inhomogeneous second-order ODE’s
d2 y dy
6 + 8y = f (x),
dx2 dx
with
(a) f (x) = 16x + 12, (b) f (x) = 5 cos x,
for which y = 1 and dy/dx = 0 at x = 0.
75
76