Lecture Notes ODEs
Lecture Notes ODEs
Course Outline
Purpose of the course
• The course aims at discuss various methods of solving different kinds of mathe-
matical problems which arise from practical applications and can be modelled by
linear or non-linear ODEs.
Course Content
ODEs provides a powerful means of summarizing various real world problems. There
are various ways which can be used to solve the proposed models. In nutshell, the
techniques can be either analytic or numeric. It is intended that, on completing the
course, students will be able to apply analytical and numerical methods to problems
which they encounter in academic and beyond. The course consists of four sections
which are as follows:
1
CHAPTER 1: First Order Differential Equations
• Introduction
• Introduction
• Introduction
• Linear transforms
• Inverse transforms
• Applications
• Euler’s method
• Runge-Kutta methods.
References
• Burden, Richard L., and Faires, Douglas J.(1993). Numerical Analysis. 5th Ed.
Boston: PWS KENT Publishing Company.
2
• Curtis, Gerald F, and Wheately, Patrick O. (1994). Applied Numerical Analysis
5th Ed. Addison-wesley Publishing Company, Reading.
• T. Akai (1996). Numerical Methods for Engineers .John Wiley & sons
• J.H. Mathews, (1992). Numerical Methods for Mathematics, Science and Engi-
neering, Prentice Hall International Editions.
3
Chapter 1
3. the angular displacement θ(t) at any time t of a rigid body pendulum can be
modelled by the ODE
d2 θ
I + mgh sin θ = 0; (1.3)
dt2
4
where I, m, g and h are constants.
• The order of a differential equation is simply the order of the highest deriva-
tive which occurs in the equation. For example, Equations (1.1) and (1.2) are
First-order differential equations while Equation (1.3) is a second-order differen-
tial equation.
f (x, y, y 0 ) = 0. (1.4)
1. Separable ODEs
2. Linear ODEs
3. Exact ODEs
• In such cases we can solve Equation (1.5) by integrating both sides with respect
to x, thereby obtaining the solution in implicit form as follows:
Z Z
dy
= h(x)dx (1.6)
g(y)
Example 1.1. Determine the general solution of the following differential equation:
y 0 = xy (1.7)
5
Solution 1.1. We can write Equation (1.7) as follows
Z Z
dy
= xdx. (1.8)
y
2 /2
y = Ae−x (1.9)
where A is a constant.
Solution 1.2. • Equation (1.10) is known as the initial value problem (IVP) since
the dependent variable has specified initial conditions (y(0) = 1.)
dy
= −y 2 sin x
Z dx Z
dy
= − sin xdx
y2
1
− = cos x + A (1.11)
y
1
• Using the initial conditions one gets A = −2. Thus the solution is y = .
2 − cos x
• For example, 2xy 0 − x2 y = sin x is of the linear type but 2xy 0 − xy 2 = sin x is
not of the linear type.
dy
+ p(x)y = g(x), y(x0 ) = y0 . (1.12)
dx
6
• In order to obtain the solution of (1.12) one has to determine an integrating
factor, say µ(x) such that after multiplying Equation (1.12) with it through out,
that is
" #
dy
µ(x) + p(x)y = µ(x)g(x), (1.13)
dx
we have the relation
" #
dy d
µ(x) + p(x)y = [µ(x)y(x)]. (1.14)
dx dx
• For the relation (1.14) to be satisfied the integrating factor should satisfy
Z
p(x)dx
µ(x) = e . (1.15)
Example 1.3. Determine the general solution of the following differential equa-
tion:
dy
+ 2y = e−x , y(0) = 3/4. (1.16)
dx
Solution 1.3. – One can easily observe that this is not separable.
Z !
y(x) = e−2x ex dx + A
7
1.5 Exact first order differential equations
• A first order differential equation is said to be exact if it is of the form
∂f (x, y) ∂f (x, y)
where M (x, y) = and N (x, y) = , and satisfies the relation
∂x ∂y
∂M (x, y) ∂N (x, y)
= . (1.22)
∂y ∂x
dy
Example 1.4. Solve 2xy − 9x2 + (2y + x2 + 1) = 0.
dx
Solution 1.4. • First let us write the Equation in the standard form, that is
∂M ∂
= (2xy − 9x2 ) = 2x,
∂y ∂y
∂N ∂
= (2y + x2 + 1) = 2x,
∂x ∂x
• The test has been confirmed we can now solve the exact DE
Z Z
M (x, y)dx = (2xy − 9x2 )dx = x2 y − 3x3 + C1 ,
Z Z
N (x, y)dy = (2y + x2 + 1)dy = y 2 + x2 y + y + C2
Solution 1.5. • First let us write the Equation in the standard form, that is
8
• Test, whether it is exact DE
∂M ∂
= (2xy 2 + 4) = 4xy,
∂y ∂y
∂N ∂
= (2x2 y − 6) = 4xy,
∂x ∂x
• The test has been confirmed we can now solve the exact DE
Z Z
M (x, y)dx = (2xy 2 + 4)dx = x2 y 2 + 4x + C1 ,
Z Z
N (x, y)dy = (2x2 y − 6)dy = x2 y 2 − 6y + C2
Then if M (x, y) and N (x, y) are homogeneous function of the same order, then
substitution can be used to solve the DE since it will transform the equation into
a simple form.
9
• If M (x, y) and N (x, y) can be written in the form
M (x, y) = xn · g1 (u),
y
N (x, y) = xn · g2 (u), where, u= . (1.25)
x
x
• In some instance it is preferable to use u = . in such case the test proving that
y
substitution leads to DE with separable variables is
M (x, y) = y n · g1 (u),
y
N (x, y) = y n · g2 (u), where, u= . (1.26)
x
by substituting u = y/x.
• One can easily locate both members M (x, y) and N (x, y), thus
M (x, y) = x2 · g1 (u),
N (x, y) = x2 · g2 (u)
10
• Integrating throughout one gets
1
log |x| + log u3 + 3u = C
3
1
log |x| = − log u3 + 3u + C
3
C
x=
(u3
+ 3u)1/3
x u + x3 · 3u = C
3 3
!3 !
y y
x3 + x3 · =C
x x
• Simplifying leads to
y 3 + 3x2 y = C.
dy
Example 1.7. Solve x2 − xy = y 2
dx
Solution 1.7. • Rewriting the equation we have
x2 dy − xydx = y 2 dx
x!2 dy = (y 2 + xy)dx
!
x2 x
y2 2
dy = y 2 1 + dx
y y
• We can observe that the system is homogeneous of degree 2 and the appropriate
substitution is u = x/y ⇒ x = uy ⇒ dx = du y + u dy
• It follows that
u2 dy = (1 + u)dx
u2 dy = (1 + u)(du y + u dy)
u2 dy = du y + u dy + u du y + u2 dy
−udy = du(y + uy)
−udy = du y(1 + u)
1 (1 + u)
− dy = du
y u
− log(y) = log(u) + u + C
11
• Substituting u = x/y one gets
!
x x
log + log(y) = − + C
y y
x
log(x) = − + C
y
x
• Finally we have y = .
C − log(x)
dy
+ p(x)y = f (x) · y n . (1.29)
dx
u = y 1−n (1.30)
(1 − n)y −n (1.31)
• Hint Note that the relationship between u = y 1−n and (1 − n)y −n , is by differen-
tiating u with respect to y.
dy
(1 − n)y −n + (1 − n)y −n p(x)y = (1 − n)y −n f (x) · y n
dx
d 1−n
y + (1 − n)y −n p(x)y = (1 − n)f (x)
dx
d
u + (1 − n)y −n p(x)y = (1 − n)f (x). (1.32)
dx
12
Example 1.8. Solve the DE y 0 + xy = xy −3 , y 6= 0.
dy
4y 3 + 4y 4 x = 4x
dx
du
+ 4xu = 4x (1.33)
dx
• Clearly we have transformed the problem into a linear DE with the integrating
2
R
4xdx
factor e = e2x
• Thus we have
2 du 2 2
e2x + 4xue2x = 4xe2x
dx Z
d 2x2 2
(ue ) = e2x 4xdx
dx
2 2
ue2x = e2x + C
2
u = 1 + Ce−2x (1.34)
2
y 4 = 1 + Ce−2x . (1.35)
Solution 1.9. • Let A(t) be the amount of the substance at time t (in per-
centage), such that at t = 0, we have A(0) = 100. and at t = 50 we have
A(50) = 98.3
13
• Since the amount of the substance decreases with time we have the relation
dA
= −kA (1.36)
dt
where k is a constant.
−4 t+4.6052
• Thus, the particular solution is A(t) = e−3.435·10 .
• Using the particular solution we have (i) 96.6% (ii) t = 307 years.
Solution 1.10. • Let TB be the temperature of the body and TM be the temper-
ature of the medium.
• Then the rate of change temperature of the body can be modelled as follows
dTB
= −k(TB − TM ), (1.38)
dt
where k is a constant.
• Thus we have TB = TM + e−0.693t+4.787 and from this function we can find the
time it takes for the body temperature to decrease to 90◦ C (ANS 2 minutes).
14
Tutorial 1.1. Attempt all questions
1. Find the solution of the equation A0 (t) + A(t) − 1 = 0 which satisfies the condition
A(0) = 0.
dv
2. Solve the equation m = −kv − mg with initial condition v(0) = 0 when k = 0.1
dt
and m = 1. (Recall that g = 9.8 meters per second per second.)
3. Let P(t) be the population size for a bacteria colony at time t. The logistic model
is that
dP
= kP (M − P ),
dt
where k > 0 and M > 0 are constants. Solve this equation when k = 1 and
M = 1000 with P (0) = 100.
dy
4. 3y + ex + (3x + cos y) =0
dx
dA
5. Solve the equation = A + 1 with the initial condition A(0) = 5.
dt
dA
6. Solve the equation = A2 + 1 with the initial condition A(0) = 1.
dt
7. Newton’s Law of Cooling states that the rate of change of temperature of a body
submersed in a bath is proportional to the difference of temperature between the
body and the bath. If a kettle of 100 degree water cools to a temperature of 80
degrees in 30 minutes when placed in a room of constant temperature 25, what is
the proportionality constant? How long will it take for the kettle to reach room
temperature?
15
Chapter 2
2.1 Introduction
• The general form of a second-order ODEs is
ay 00 + by 0 + cy = f (x), (2.1)
where the coefficients a, b and c are constants. If f (x) = 0, then equation (2.1) is
called a Homogenous equation otherwise it an Inhomogenous equation.
ay 00 + by 0 + cy = 0. (2.2)
• The solution of Equation ( 2.2) entails finding two linearly independent solutions,
multiply each by a constant and then add them.
16
• Th quadratic equation (2.3) is called the auxiliary equation or the characteristic
equation of Equation (2.2) and has the same coefficients as Equation (2.2).
• One can observe that there are 3 possible outcomes based on the output of the
discriminant b2 − 4ac,
1. If b2 − 4ac > 0, the auxiliary equation has two distinct real roots m1 and m2
giving solutions em1 x and em2 x , such that the general solution of (2.2) is
Solution 2.1. – The auxiliary equation for the given ODE has the form
m2 + 5m + 6 = (m + 2)(m + 3) = 0. (2.8)
17
– Thus the general solutions is y(x) = Ae−2x + Be−3x .
7
– Solving Equation (2.11) leads to A = 5
and B = − 57 .
3. 4y 00 − 5y 0 = 0 y(−2) = 0, y 0 (2) = 7.
ay 00 + by 0 + cy = f (x). (2.12)
• The solution of Equation (2.12) constitute two parts (i) the complementary func-
tion yc and the particular solution yp , that is y(x) = yc + yp .
18
• The particular solution is obtained by various methods outlined below depending
on the type of the function f (x).
y 00 + 5y 0 + 6y = 12x + 4. (2.13)
0 + 5a + 6(ax + b) ≡ 12x + 4
6ax + (5a + 6b) ≡ 12x + 4. (2.14)
– To determine the particular solution one may be tempted to use a linear func-
tion y(x) = Ax + b???
3A ≡ 6x (2.16)
19
– Clearly we can observe that this does not work? Hence, in this case a quadratic
function is appropriate.
2a + 3(2ax + b) ≡ 6x
6ax + (2a + 3b) ≡ 6x (2.17)
– However, for this ODE any constant value of c can also work??
– Thus, y = 92 (1 − e−3x ) + x2 − 32 x.
– Substituting leads to
– Thus, yp = 53 e2x .
20
Remark 2.2. – Determine the solution of the differential equation y 00 + 5y 0 +
6y = 12e−2x .
– If we choose y = ae−2x it will not work because the general solution has this
component already, therefore a more suitable function is y = axe−2x .
y 00 + 5y 0 + 6y = 26 cos 2x.
– Substituting gives
(−4a cos 2x − 4b sin 2x) + 5(−2a sin 2x + 2b cos 2x) + 6(cos 2x + b sin 2x) ≡ 26 cos 2x.
– Differential equations such as y 00 +5y 0 +6y = xemx and y 00 +5y 0 +6y = emx sin 3x
can be reduce to cases previously considered by putting y = v(x)emx (i.e.
reformulating the differential equation in terms of a new dependent variable
v) which effectively removes the exponential.
21
Example 2.6. Determine the solution of the differential equation
v 00 + 3v = 4 sin x. (2.22)
y 00 − y 0 − 2y = 4,
22
y 00 − y 0 − 2y = 6ex ,
y 00 − y 0 − 2y = sin 2x,
separately, and then the particular integral for Equation (2.23) is just the
sum of the three individual particular integrals.
(a) y 00 − y 0 − 6y = 12x
(b) y 00 + 7y 0 + 12 = 4e2x
(c) y 00 − 2y 0 + 5y = 20 sin 2x
(d) y 00 + 4y = 20 sin 2x
(a) µ < m,
(b) µ = m,
(c) µ > m.
23
Chapter 3
Laplace transform
3.1 Introduction
The Laplace Transform was first used by and named after Pierre Simon Laplace1 , French
mathematician and astronomer. Basically, a Laplace transform will convert a function
in some domain into a function in another domain, without changing the value of the
function. For example, let’s take this function where a Laplace transform is used to
convert a function of time to a function of frequency. Laplace transforms are invaluable
for any engineer’s mathematical toolbox as they make solving linear ODEs and related
initial value problems, as well as systems of linear ODEs, much easier. Applications
abound : electrical networks, springs, mixing problems, signal processing, and other
areas of engineering and physics.
24
medium (FM/AM stereo, 2-way radio sets, cellular phones). When information is sent
over medium such as cellular phones, they are first converted into time-varying wave,
and then it is super-imposed on the medium. In this way, the information propagates.
Now, at the receiving end, to decipher the information being sent, medium waves time
functions are converted to frequency functions. This is a simple real life application of
Laplace Transform.
When the defining integral (3.1) converges, the result is a function of s. We shall use
lowercase letter to denote the function being transformed and the corresponding capital
letter to denote its Laplace transform, for example
provided s > 0. In other words, when s > 0, the exponent −sb is negative and e−sb → 0
as b → ∞. When s < 0, the integral is divergent.
25
3.2 L is a Linear Transform
For a sum of functions we can write
Z ∞ Z ∞ Z ∞
−st −st
e [αf (t) + βg(t)]dt = α e f (t)dt + β e−st g(t)dt,
0 0 0
Solution: This piece-wise continuous function. Since f is defined in two pieces, L {f (t)}
is expressed as the sum of two integrals
Z ∞
L {f (t)} = e−st f (t)dt
Z0 3 Z ∞
−st
= e (0)dt + e−st (2)dt
0 3
∞
2e−st
= −
s 3
2e−3s
= , s > 0.
s
f (t) = L −1 {F (s)}.
27
where F and G are the transforms of some functions f and g.
1
Example 3.4. Evaluate L −1
.
s5
Solution: It follows
1 1 −1 4! 1
L −1
5
= L 5
= t4 .
s 4! s 24
3s + 5
Example 3.5. Evaluate L −1 .
s2 + 7
Solution: The given function of s can be written as two expressions by means of term-
wise division
3s + 5 3s 5
2
= 2 + 2 .
s +7 s +7 s +7
From the linearity property of the inverse Laplace transform, we then have
( √ )
3s + 5 s 5 7
L −1 2
= 3L −1 2
+ √ L −1 2
s +7 s +7 7 s +7
√ 5 √
= 3 cos 7t + √ sin 7t.
7
s+1 A B C D E
= + 2+ + +
s2 (s
+ 2) 3 s s s + 2 (s + 2) 2 s + 2)3
1 1 1 1
so that A = − , B = , C = , D = 0 and E = − . Hence
16 8 16 4
s+1 1/16 1/8 1/16 1/4
L −1
= L −1
− + 2 + −
s2 (s + 2)3 s s s + 2 (s + 2)3
1 −1 1 1 −1 1 1 −1 1 1 −1 2
= − L + L + L { }− L
16 s 8 s2 16 s+2 8 (s + 2)3
1 1 1 1
= − + t + e−2t − t2 e−2t .
16 8 16 8
3s − 2
Example 3.7. Evaluate L −1
.
s3 (s2 + 4)
28
3.5 Translation Theorems and Derivatives of a Trans-
form
Definition 3.2 (First Translation Theorem). If F (s) = L {f (t)} and a is any real
number, then
L {eat f (t)} = F (s − a).
29
3.6 Transforms of Derivatives, Integrals and Peri-
odic Functions
Our goal is to use the Laplace transform to solve certain kinds of differential
2 equa-
dy dy
tions. To that end we need to evaluate quantities such as L and L . For
dt dt2
example, if f 0 is continuous for t ≥ 0, then integration by parts gives
Z ∞ ∞ Z ∞
L {f (t)} =
0 −st 0 −st
e f (t)dt = e f (t) +s e−st f (t)dt
0 0 0
= −f (0) + sL {f (t)},
or
L {f 0 (t)} = sF (s) − f (0).
Similarly
Z ∞ ∞ Z ∞
L {f (t)} =
00 −st 00
e f (t)dt = e −st 0
f (t) +s e−st f 0 (t)dt
0 0 0
0 0
= −f (0) + sL {f (t)}
or
L {f 00 (t)} = s2 F (s) − sf (0) − f 0 (0).
3.7 Applications
Since L {y (n) (t)}, n > 1, depends on y(t) and its n − 1 derivatives evaluated at t = 0,
the Laplace transform is ideally suited to initial valued problems for linear differential
equations with constant coefficients. This kind of differential equation can be reduced
dto an algebraic equation in the transformed function Y (s). To see this, consider the
initial value problem
dn y dn−1 y dy
an n
+ a n−1 n−1
+ · · · + a1 + a0 y = g(t)
dt dt dt
0 (n−1)
y(0) = y0 , y (0) = y1 , . . . , y (0) = yn−1 ,
30
where ai , i = 0, 1, 2, . . . , n and y0 , y1 , . . . , yn−1 are constants. By the linearity property
of the Laplace transform, we can write
n n−1
d y d y
an L n
+ an−1 L + · · · + a0 L {y} = L {g(t)}.
dt dtn−1
Therefore
an [sn Y (s) − sn−1 y(0) − · · · − y (n−1) (0)] + an−1 [sn−1 Y (s) − sn−2 y(0) − · · · y (n−2) (0)]
+ · · · + a0 Y (s) = G(s)
where Y (s) = L {y(t)} and G(s) = {g(t)}. By solving for Y (s), we find y(t) by deter-
mining the inverse transform
y(t) = L −1 {Y (s)}.
dy
Example 3.11. Solve − 3y = e2t , y(0) = 1.
dt
Solution: We first take the transform of each member of the given differential equation,
dy
L − 3L {y} = L {e2t }.
dt
dy 1
We then use L = sY (s) − y(0) = sY (s) − 1 and L {e2t } = . Solving
dt s−2
1
sY (s) − 1 − 3Y (s) =
s−2
s−1 −1 2
Y (s) = = + ,
(s − 2)(s − 3) s−2 s−3
and so
−1 1 −1 1
y(t) = −L + 2L
s−2 s−3
. Then it follows that
y(t) = −e2t + 2e3t .
2
s2 Y (s) − sy(0) − y 0 (0) − 6[sY (s) − y(0)] + 9Y (s) = .
(s − 3)3
31
Using the initial conditions and simplifying, give
2
(s2 − 6s + 9)Y (s) = 2s − 6 +
(s − 3)3
2
(s − 3)2 Y (s) = 2(s − 3) +
(s − 3)3
2 2
Y (s) = +
s − 3 (s − 3)5
Thus
1 2 4!
y(t) = 2L −1
+ L −1 .
s−3 4! (s − 3)5
Recall from the first translation theorem that
( )
4
L −1 = t4 e3t .
s5
s→s−3
Hence, we have
1 4 3t
y(t) = 2e3t + te .
12
Example 3.13. Solve y 00 + 4y 0 + 6y = 1 + e−t , y(0) = 0, y 0 (0) = 0.
Solution: L {y 00 } + 4L {y 0 } + 6L {y} = L {1} + L {e−t }.
1 1
s2 Y (s) − sy(0) − y 0 (0) + 4[sY (s) − y(0)] + 6Y (s) = +
s s+1
2s + 1
(s2 + 4s + 6)Y (s) =
s(s + 1)
2s + 1
Y (s) = .
s(s + 1)(s2 + 4s + 6)
In preparation for taking the inverse transform, we fix up Y (s) in the following manner,
Finally, we obtain
( √ )
1 −1 1 1 −1 1 1 −1 s+2 2 2
y(t) = L = L − L − √ L −1
6 s 3 s+1 2 (s + 2)2 + 2 3 2 (s + 2)2 + 2
√
1 1 −t 1 −2t √ 2 √
= + e − e cos 2t − sin 2t.
6 3 2 3
32
Tutorial 3.1. 1. Find L {f (t)}.
(i) f (t) = et+7 (ii) f (t) = t2 e3t (iii) f (t) = e−2t−5 (iv) f (t) = t cos t (v)
f (t) = te4t .
5. Use the Laplace transform to solve the given differential equation subject to the
indicated initial conditions.
(i) y 00 − 2y 0 = et sinh t, y(0) = 0, y 0 (0) = 0 (ii) y 00 − y 0 = et cos t, y(0) = 0, y 0 (0) =
0
(iii) y 00 +16y = 1, y(0) = 1, y 0 (0) = 2 (iv) y 00 −4y 0 +4y = t3 e2t , y(0) = 0, y 0 (0) = 0
(v) y 00 − 2y 0 + 5y = 1 + t, y(0) = 0, y 0 (0) = 4 (vi) y 00 − 6y 0 + 9y = t, y(0) =
0, y 0 (0) = 1
33
Chapter 4
4.1 Introduction
The analytical methods of solving differential equations are applicable to a limited class
of equations. Quite often, differential equations modelling real world problems, do not
belong to any of these familiar types and as such one is obliged to resort to numerical
methods for a solution.
• If we subdivide the interval [a, b] into n subintervals and select mesh points, we
have
xk+1 = xk + h, k = 0, 1, 2, · · · , n − 1
where
b−a
h= , x0 = a, and xn = b.
n
34
• Using Taylor’s theorem, we have
y(xk+1 ) = y(xk + h)
1 2 00 1
= y(xk ) + hy 0 (xk ) + h y (xk ) + · · · + hn y (n) (xk ) + · · · (4.2)
2! n!
• If the step size h is chosen small enough, we may neglect higher order terms of
(4.2), that is,
y(xk+1 ) = y(xk + h)
1 2 00 1
= y(xk ) + hy 0 (xk ) + h y (xk ) + · · · + hn y (n) (xk ) (4.3)
2! n!
• Equation (4.3) is called the Taylor’s formula of order n and it can be used to
compute the numerical solution of the IVP (4.1).
Example 4.1. Use Taylor’s method of order 2 to solve the following initial value problem
• We know that
• Thus,
1
y(xk+1 ) = y(xk ) + hy[y(xk ) + exk ] + h2 [y(xk ) + 2exk ]
2
1 2
= 1 + h + h yk + (h + h2 )exk .
2
35
• For k = 0 we have
1
y1 = 1 + 0.001 + (0.001) y0 + (0.001 + (0.001)2 )ex0
2
2
= 1.0010005y0 + 0.001001ex0
= 1.001(1) + 0.001001(1)
= 1.0020015.
• For k = 1 we have
y2 = 1.001y1 + 0.001001ex1
= 1.0010005(1.0020015) + 0.001001e0.001
= 1.004006004001417.
• For k = 2 we have
y3 = 1.0010005y1 + 0.001001ex1
= 1.0060135160117556.
y(x) = ex (1 + x).
36
• Recall that y 0 (x) = f (x, y), thus (4.4) becomes
Example 4.2. Use Euler’s method to solve the following initial value problem
• Thus
• If we subdivide the interval [a, b] into n subintervals of equal length h and set
b−a
h= , so that xk+1 = xk + h for k = 0, 1, 2, 3, · · · .
n
• Integrating y 0 = f (x, y) over [xk , xk+1 ] we get
Z xk+1 Z xk+1
0
y dx = f (x, y)dx
xk xk
h
y(xk+1 ) − y(xk ) = [f (xk , yk ) + f (xk+1 , yk+1 )]
2
h
= y(xk ) + [f (xk , yk ) + f (xk+1 , yk+1 )]. (4.5)
2
37
• Equation (4.5) is called the modified Euler’s method or the Euler-Cauchy’s method.
Example 4.3. Use Euler-Cauchy’s method to solve the following initial value problem
• Since we are not aware of y1 for to use on f (x1 , y1 ) we will first use Euler’s method
to find y1 , that is;
yk+1 = yk + hf (xk , yk )
y1 = y0 + hf (x0 , y0 )
= −1 + 0.1(1) = −0.9.
• Now
• Thus
0.1
y1 = −1 + [1 + 0.7] = −0.915.
2
• For k = 1 we have
h
y2 = y1 + [f (x1 , y1 ) + f (x2 , y2 )]
2
38
• Thus
0.1
y2 = −0.915 + [0.715 + 0.4435] = −0.857075.
2
• Thus
yk+1 = yk + hf (xk , yk ).
k1 = f (xk , yk )
k2 = f (xk+1 , yk+1 )
= f (xk + h, yk + hk1 ).
39
4.5.3 Runge-Kutta method of order 3
• It is given by
h
yk+1 = yk + [k1 + 4k2 + k3 ]
6
where
k1 = f (x
k , yk )
h h
k2 = f xk + , yk + k1
2 2
k3 = f (xk + h, yk − hk1 + 2hk2 ).
Example 4.4. Use Runge-Kutta’s method of order 3 (RK-3) to solve the following initial
value problem
0 , y0 ) = f (0, −1)
k1 = f (x = −2(0) − (−1) = 1,
h h
k2 = f x0 + , y0 + k1 = f (0.05, −0.95) = −2(0.05) − (−0.95) = 0.85
2 2
k3 = f (x0 + h, y0 − hk1 + 2hk2 ) = f (0.1, −0.93) = −2(0.1) − (−0.93) = 0.73
• Thus
0.1
y1 = −1 + [1 + 4(0.85) + 0.73] = −0.9145.
6
• For k = 1
1 , y1 ) = f (0.1, −0.9145)
k1 = f (x = −2(0.1) − (−0.9145) = 0.7145,
h h
k2 = f x1 + , y1 + k1 = f (0.15, −0.878775) = −2(0.15) − (−0.878775) = 0.578775.
2 2
k3 = f (x1 + h, y1 − hk1 + 2hk2 ) = f (0.2, −0.870195) = −2(0.1) − (−0.93) = 0.470195
• Thus
0.1
y2 = −0.9145 + [0.7145 + 4(0.578775) + 0.470195] = −0.8561700833333333.
6
40
• Therefore
k1 = f (x
k , yk )
h h
k2 = f xk + , yk + k1
2 2
h h
k3 = f xk + , yk + k2
2 2
k4 = f (xk + h, yk + hk3 ).
Example 4.5. Use Runge-Kutta’s method of order 3 (RK-3) to solve the following initial
value problem
0 , y0 ) = f (0, −1)
k1 = f (x = −2(0) − (−1) = 1,
h h
k2 = f x0 + , y0 + k1 = f (0.05, 0.95) = 0.85,
2 2
h h
k3 = f x0 + , y0 + k2 = f (0.05, −0.9575) = 0.8575,
2 2
k4 = f (x0 + h, y0 + hk3 ) = f (0.1, −0.91425) = 0.71425.
• Thus
0.1
y1 = −1 + [1 + 2(0.85) + 2(0.8575) + 0.71425] = −0.9145125.
6
41
4.6 Second order differential equations
• Majority of real life problems can be presented as a system of first order differential
equations, that is;
y10 = f1 (x, y1 , y2 , · · · , yp ),
y20 = f2 (x, y1 , y2 , · · · , yp ),
.. .
. = ..
yp0 = fp (x, y1 , y2 , · · · , yp ).
y 00 + 3y 0 + 2y = ex , y(0) − 1, y 0 (0) = 2
• Thus
u0 = v u(0) = 1
v 0 = −2u − 3v + ex , v(0) = 2
(ii) Reduce the above differential equation to a system of first order differential equa-
tions.
42
(iii) Use Euler’s method with h = 0.05 to estimate y(0.1).
Solution 4.7. (i) It can easily be verified that the analytical solution is
y(x) = ex − e−x − x.
u0 = v, u(0) = 0
v 0 = u + x, v(0) = 1
un+1 = un + hf (xn , un , vn )
vn+1 = vn + hg(xn , un , vn )
• For n = 0, we have
u1 = u0 + hf (x0 , u0 , v0 )
= 0 + 0.05f (0, 0, 1)
= 0.05
v1 = v0 + hg(x0 , u0 , v0 )
= 1 + 0.05g(0, 0, 1)
= 1
• For n = 1, we have
u2 = u1 + hf (x1 , u1 , v1 )
= 0.05 + 0.05f (0.05, 0.05, 1)
= 0.05 + 0.05(1) = 0.1
v2 = v1 + hg(x1 , u1 , v1 )
= 1 + 0.05g(0.05, 0.05, 1)
= 1 + 0.05(0.1)
= 1.005.
43
• The analytical solution is y(0.1) = 0.100334.
u0 = v u(0) = 0
v 0 = u + x, v(0) = 1
• Let
f (xn , un , vn ) = vn
g(xn , un , vn ) = un + xn
h
un+1 = un + [k1 + 2k2 + 2k3 + k4 ]
6
h
vn+1 = vn + [l1 + 2l2 + 2l3 + l4 ]
6
where
k1 = f (xn , un , vn ),
l1 = g(xn , un , vn ),
44
h h h
k2 = f xn + , un + k1 , vn + l1 ,
2 2 2
h h h
l2 = g xn + , un + k1 , vn + l1 ,
2 2 2
h h h
k3 = f xn + , un + k2 , vn + l2 ,
2 2 2
h h h
l3 = g xn + , un + k2 , vn + l2 ,
2 2 2
• Now
k1 = f (x0 , u0 , v0 ) = f (0, 0, 1) = 1,
l1 = g(x0 , u0 , v0 ) = g(0, 0, 1) = u0 + x0 = 0.
k2 = f (0.025, 0.025, 1) = 1,
l2 = g(0.025, 0.025, 1) = 0.05.
• Thus
0.05
u1 = 0 + [1 + 2(1) + 2(1.00125) + 1.0025] = 0.0500417.
6
45
0.05
v1 = 1 + [0 + 2(0.05) + 2(0.05) + 0.1000625] = 1.0025005208333333
6
• Recall that the exact solution is y(0.05) = e0.05 −e−0.05 −0.05 = 0.0500416718753101.
y 0 = xy + x, y(2) = 1.
(c) Estimate the values for y when x = 2.1 and x = 2.2 with h = 0.1.
y 0 = x + y, y(0) = 1
(b) Using the following methods to estimate y(0.2), consider a step size of 0.1
46