0% found this document useful (0 votes)
246 views25 pages

Numerical Methods in Solving Initial Value Problems of ODEs

It is about the different numerical methods in solving an initial value problem of a 1st order ODE. Among the methods included are: Euler's method, Improved Euler's method, Heun's method, Midpoint method, Ralston's method, classical 3rd order and 4th order RK methods, and Butcher's method.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
246 views25 pages

Numerical Methods in Solving Initial Value Problems of ODEs

It is about the different numerical methods in solving an initial value problem of a 1st order ODE. Among the methods included are: Euler's method, Improved Euler's method, Heun's method, Midpoint method, Ralston's method, classical 3rd order and 4th order RK methods, and Butcher's method.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Ching, Robby Andre July 3, 2020

Numerical Methods in solving Initial value O.D.Es

One of the fundamental concepts in Differential Calculus is as follows: “The derivative of a


function gives the slope value of the tangent lines on the points of its curve.” Then, for a given first-order
𝑑𝑦
differential equation 𝑑𝑥 , and there exists a solution for it, then that solution must be differentiable and
continuous for a given interval I, having tangent lines on every point of its curve [1].
𝑑𝑦
𝑓(𝑥, 𝑦) =
𝑑𝑥
The function 𝑓 is called the Slope function or Rate function. Its value for a given point (𝑥, 𝑦) is the
slope of a line segment tangent to it, called Lineal element. If we systematically evaluate the function 𝑓
over a rectangular grid of points in the xy-plane such that a lineal element is drawn for every point (𝑥, 𝑦)
over a given range for that grid, we produce what is called Direction field or Slope field of the 1st order
differential equation 𝑓 (𝑥, 𝑦). A Direction field is a set of lineal elements. This Direction field visually shows
the appearance of a family of solution curves for that differential equation. Suppose we have the following
differential equation with its computer-generated
Direction field [1].
𝑑𝑦 [1]
= 𝑥2 − 𝑦 2
𝑑𝑥
Evaluating how the Direction field was generated can be
𝑑𝑦
done by making use of the realization that at 𝑑𝑥 = 0 there
would be a change of slope from left to right (of its x value)
and from top to bottom (of its y value):

Where:
𝑑𝑦
𝑥0 𝑎𝑛𝑑 𝑦0 = 𝑣𝑎𝑙𝑢𝑒𝑠 𝑡ℎ𝑎𝑡 𝑤𝑜𝑢𝑙𝑑 𝑚𝑎𝑘𝑒 =0
𝑑𝑥
𝑥→ = 𝑥 𝑣𝑎𝑙𝑢𝑒 𝑡𝑜 𝑡ℎ𝑒 𝑟𝑖𝑔ℎ𝑡 𝑜𝑓𝑥0 𝑎𝑡 𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡 𝑦
𝑑𝑦
= 0 would give a horizontal lineal
𝑥← = 𝑥 𝑣𝑎𝑙𝑢𝑒 𝑡𝑜 𝑡ℎ𝑒 𝑙𝑒𝑓𝑡 𝑜𝑓𝑥0 𝑎𝑡 𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡 𝑦 𝑑𝑥
element. From the given D.E., it can be seen
𝑦↑ = 𝑦 𝑣𝑎𝑙𝑢𝑒 𝑎𝑏𝑜𝑣𝑒 𝑦0 𝑎𝑡 𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡 𝑥 that as long as x and y values are the same, it
𝑑𝑦
𝑦↓ = 𝑦 𝑣𝑎𝑙𝑢𝑒 𝑏𝑒𝑙𝑜𝑤 𝑦0 𝑎𝑡 𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡 𝑥 would give 𝑑𝑥
= 0. This is bracketed in the
direction field.
a. (1st Quadrant) 𝑥0 = 𝑦0 b. (2nd Quadrant) −𝑥0 = 𝑦0
𝑑𝑦 𝑑𝑦
• 𝑥→ ; 𝑑𝑥
=+ • 𝑥→ ; 𝑑𝑥
=−
𝑑𝑦 𝑑𝑦
• 𝑥← ; 𝑑𝑥
=− • 𝑥← ; 𝑑𝑥
=+
𝑑𝑦 𝑑𝑦
• 𝑦↑ ; 𝑑𝑥
=− • 𝑦↑ ; 𝑑𝑥
=−
𝑑𝑦 𝑑𝑦
• 𝑦↓ ; 𝑑𝑥
=+ • 𝑦↓ ; 𝑑𝑥
=+
c. (3rd Quadrant) −𝑥0 = −𝑦0 d. (4th Quadrant) −𝑥0 = −𝑦0
𝑑𝑦 𝑑𝑦
• 𝑥→ ; 𝑑𝑥
=− • 𝑥→ ; 𝑑𝑥
=+
𝑑𝑦 𝑑𝑦
• 𝑥← ; 𝑑𝑥
=+ • 𝑥← ; 𝑑𝑥
=−
𝑑𝑦 𝑑𝑦
• 𝑦↑ ; 𝑑𝑥
=+ • 𝑦↑ ; 𝑑𝑥
=+
𝑑𝑦 𝑑𝑦
• 𝑦↓ ; 𝑑𝑥
=− • 𝑦↓ ; 𝑑𝑥
=−

Generating the whole Direction field could also be done in a more tedious manner, by solving the
𝑑𝑦
value of 𝑑𝑥
for all possible values of x and y in the rectangular grid and determine if the value is positive
or negative to determine the direction of the lineal element at that point. The importance of this direction
field is that it gives us an idea on what the solution curve for the given D.E. looks like. This is especially
helpful if the given D.E. cannot be solved using the presented Analytical methods (for 1st order D.E., these
methods include variable separable, exact D.E., and homogeneous equations). That is, the direction field
is the foundation of the Numerical methods in solving Differential equations [1].

[1]

Suppose we have the following initial conditions:


a. 𝑦(−2) = 1 : Green curve

b. 𝑦(0) = 3 : Yellow curve

c. 𝑦(−2.5) = −2 : Orange curve

Using the Direction field, one can visually show (or


assume) the appearance of the solution curve at given
initial condition.

The behavior of a solution curve near a certain point (initial conditions) is best observed if the
differential equation is autonomous. An Autonomous Ordinary Differential Equation, a third type of
ordinary D.E. (linear and non-linear being the other two types), is when the independent variable does
not appear explicitly. That is, it only depends on the dependent variable. This kind of Ordinary differential
equations may appear in Physics as equations where the variable of interest (dependent variable) does
not change in time (independent variable). Let us evaluate the behavior of the following autonomous 1 st
order differential equation [1].
𝒅𝒚
= 𝒚𝒍𝒏(𝒚 + 𝟐) → 0 = 𝑦𝑙𝑛(𝑦 + 2) → 𝒚 = 𝟎; ln(𝑦 + 2) = 0 → 𝒚 = −𝟏
𝒅𝒙

𝑑𝑦
The Critical Point/s are y values that will make 𝑑𝑥
= 0. For the given differential equation, the
critical points are 𝒚 = 𝟎; −𝟏. The critical points, as in differential calculus, are horizontal asymptotes that
tell what the solution curve behaves like if it approaches that critical point or a non-finite value (that is,
infinity). For the given D.E., we have the following behavior. Note that the differential equation only exists
at y > -2 [1].

Interval/ Sample initial 𝒅𝒚 Solution curve Lineal Element


Sign of 𝒅𝒙
Subregion condition (y value) behavior Direction
0<y<∞ 1 Positive (+) Increasing Points upward
-1 < y < 0 -0.5 Negative (-) Decreasing Points downward
-2 < y < -1 -1.5 Positive (+) Increasing Points upward

The solution curves would only be affected by the y value of the initial condition because the
differential equation only depends on the y variable. The Direction field of the given differential equation
is shown below. A generalization of solution curve behavior base on the observation on the sample initial
conditions could be made as follows [1]:

a. If the solution curve is only bounded by one Equilibrium solution


• It is Increasing when the y values would assume the highest possible values as x approaches X,
the maximum value for x (normally it is ∞)
• It is Decreasing when the y values would assume the lowest possible values as x approaches X,
the maximum value for x (normally it is ∞)
b. If the solution curve is sandwiched between two Equilibrium solutions
• It is Increasing when y values would assume the highest possible values as x approaches X, the
maximum value for x (normally it is ∞) and would assume the lowest possible values as x
approaches -X, the minimum value for x (normally it is -∞)
• It is Decreasing when y values would assume the lowest possible values as x approaches X, the
maximum value for x (normally it is ∞) and would assume the highest possible values as x
approaches -X, the minimum value for x (normally it is -∞)

[2] For an initial condition of (0, 1), which


is in the subregion of 0 < y < ∞, its
solution curve behaves increasingly. As
x ->∞, y would approach the highest
possible value, which in this subregion
is ∞. It is bounded below by the
equilibrium solution y(x) = 0, and so
the curve would approach it as x -> -∞
[1].

Note that this behavior will be true for


any initial conditions as long as the y
value is in the given subregion or
interval. See the conclusions below [1].
[2] For an initial condition of (0, -0.5), which
is in the subregion of -1 < y < 0, its
solution curve behaves decreasingly. As
x ->∞, y would approach the lowest
possible value, which in this subregion is
-1, as being bonded below by y(x) = -1.
As x -> -∞, y would approach the highest
possible value, which in this subregion is
0, as being bonded above by y(x) = 0 [1].

[2] For an initial condition of (0, -1.5),


which is in the subregion of -2 < y < -1,
its solution curve behaves increasingly.
As x ->∞, y would approach the
highest possible value, which in this
subregion is -1, as being bounded
above by the equilibrium solution y(x)
= -1. It would approach the lowest
possible value, which is y = -2, it being
the lower bound of the subregion [1].

The critical point provides the Equilibrium solution 𝑦(𝑥) = 𝑐 and therefore also called Equilibrium
point. Base on the critical points, the following conclusions can be drawn [1]:

• A solution curve stays in its subregion and cannot cross the Equilibrium solution for any values of
x. So, for initial conditions whose points have y values between 0 and ∞ for any values of x, then
its corresponding solution curves only stay in that subregion.
𝑑𝑦
• The sign of 𝑑𝑥 cannot change in a subregion.
𝑑𝑦
• The only possible signs of 𝑑𝑥 in a subregion are positive and negative. Thus, a curve can only either
behave as increasing or decreasing, making it monotonic.
• If the solution curve 𝑦(𝑥) is bounded above by a critical point or bounded below by a critical point,
it would approach one of the equilibrium solutions either as 𝑥 → −𝑋 or 𝑥 → +𝑋. If it is
sandwiched between two critical points, then its solution curve would approach both the
equilibrium solutions 𝑦(𝑥) = 𝑐1 and 𝑦(𝑥) = 𝑐2 , one as 𝑥 → −𝑋 and the other, 𝑥 → +𝑋.

The green line segments are the lineal elements. It can be seen that if the solution curve behavior
in a subregion is increasing, the lineal elements point upward, while they point downward if the
behavior is decreasing. A critical point is said to be Asymptotically Stable or Attractor if the subregions
above and below it has lineal elements pointing towards it (upper points downward, lower points
upward). Meanwhile, a critical point is said to be Asymptotically Unstable or Repeller if the
subregions above and below it has lineal elements pointing away from it (upper points upward, lower
points downward). An Asymptotically Semi-stable is achieved when both regions either point upward
or downward. In the diagrams, it can be seen that the critical point 0 is a Repeller while the critical
point -1 is an Attractor [1].

Euler’s Method

As was discussed earlier, if a 1st order ordinary differential equation cannot be solved using any
of the presented analytical methods, numerical methods could be employed to approximate the solution
curve. The first numerical method is the Euler’s method. We have seen that a set of lineal elements
(Direction field), which are line segments that are tangent to points along a solution curve, can describe
the behavior and visually depict the appearance of the solution curve. The Euler’s method utilizes this
realization. It approximates the y values for a given x values of a solution curve for a 1 st order ordinary
differential equation with the y values of their lineal elements [1].
𝑑𝑦
Let 𝑓(𝑥, 𝑦) =be the 1st Order D.E. and 𝑦(𝑥0 ) = 𝑦0 be the initial conditions. Then, 𝑓(𝑥0 , 𝑦0 ) is
𝑑𝑥
the corresponding slope value of the lineal element tangent to the point (𝑥0 , 𝑦0 ). The unknown solution
curve 𝑦(𝑥) at 𝑥 = 𝑥0 can be linearized by [1]:
𝑑𝑦
𝑦 ≈ 𝐿 (𝑥) = 𝑦0 + 𝑑𝑦 = 𝑦0 + 𝑑𝑥 → 𝒚(𝒙) ≈ 𝑳(𝒙) = 𝒚𝟎 + 𝒉𝒇(𝒙𝟎 , 𝒚𝟎 )
𝑑𝑥

The h is a small increment or a small difference value equal to


[1]
𝒙 − 𝒙𝟎. That is, the approximation of the y values at the given x values
near the initial condition gets better if the value of h gets smaller and
smaller. In the diagram, the pink line segment is the lineal element or
the tangent line of the initial condition (𝑥0 , 𝑦0 ). The 𝑦1 value is
computed using the equation of this tangent line, which is 𝐿 (𝑥1 ), where
𝑥1 = 𝑥0 + ℎ. Notice that there is an error value because 𝑦1 = 𝐿(𝑥1 ) is
only an approximation to the real value of 𝑦1 in the real solution curve.
Starting with the initial condition, we then have [1]:

[3] 𝒚𝟏 ≈ 𝐿(𝑥1 ) = 𝑦0 + ℎ𝑓(𝑥0 , 𝑦0 )


𝒚𝟐 ≈ 𝐿(𝑥2 ) = 𝑦1 + ℎ𝑓(𝑥1 , 𝑦1 )

y3 ≈L(x3 )=y +hf(x2 ,y2 )


2

.
.
.
𝒚𝒏+𝟏 ≈ 𝑳(𝒙𝒏+𝟏 ) = 𝒚𝒏 + 𝒉𝒇(𝒙𝒏 , 𝒚𝒏 )
𝑑𝑦 𝑦
Sample # 1: 𝑑𝑥 = 𝑥𝑦 2 − 𝑥 ; 𝑦(1) = 1

if 𝑎. ) ℎ = 0.10 𝑎𝑛𝑑 𝑢𝑝 𝑡𝑜 𝑛 = 10; 𝑏. ) ℎ = 0.05 𝑎𝑛𝑑 𝑢𝑝 𝑡𝑜 𝑛 = 20

The following 1st order differential equation cannot be solved by any of the analytical methods
presented. Thus, we can only use numerical methods to approximate the solution curve given the initial
condition. The Euler’s method is done as follows.
𝑦𝑛
𝑦𝑛+1 ≈ 𝐿(𝑥𝑛+1 ) = 𝑦𝑛 + ℎ𝑓(𝑥𝑛 , 𝑦𝑛 ) → 𝑦(𝑥𝑛+1 ) ≈ 𝐿(𝑥𝑛+1 ) = 𝑦𝑛 + ℎ (𝑥𝑛 𝑦𝑛 2 − )
𝑥𝑛
a.) h=0.10 and up to n=10

Sample calculations:
𝑦0 1
𝑛 = 0: 𝑦1 ≈ 𝐿(𝑥1 ) = 𝑦0 + ℎ (𝑥0 𝑦0 2 − ) = 1 + 0.10 ((1 ∙ 12 ) − ) = 𝟏. 𝟎𝟎𝟎𝟎
𝑥0 1
𝑦1 1.0000
𝑛 = 1: 𝑦2 ≈ 𝐿(𝑥2 ) = 𝑦1 + ℎ (𝑥1 𝑦1 2 − ) = 1.0000 + 0.10 ((1.1 ∙ 1.00002 ) − ) =1.0191
𝑥1 1.1

𝑦2 1.0191
𝑛 = 2: 𝑦3 ≈ 𝐿(𝑥3 ) = 𝑦2 + ℎ (𝑥2 𝑦2 2 − ) = 1.0191 + 0.10 ((1.2 ∙ 1.01912 ) − ) =1.0588
𝑥2 1.2

The following tabulation was done using Excel:

Euler’s Formula for h=0.10 Sample 1


𝒏 𝑥𝑛 𝑦𝑛 𝑦𝑛+1 𝑓 (𝑥𝑛 , 𝑦𝑛 )
0 1 1.0000 1.0000 0.0000
1 1.1 1.0000 1.0191 0.1909
2 1.2 1.0191 1.0588 0.3970
3 1.3 1.0588 1.1231 0.6429
4 1.4 1.1231 1.2194 0.9636
5 1.5 1.2194 1.3612 1.4176
6 1.6 1.3612 1.5726 2.1139
7 1.7 1.5726 1.9005 3.2791
8 1.8 1.9005 2.4451 5.4456
9 1.9 2.4451 3.4523 10.0720
10 2 3.4523 5.6633 22.1101

b.) h=0.05 and up to n=20

Sample calculations:
𝑦0 1
𝑛 = 0: 𝑦1 ≈ 𝐿(𝑥1 ) = 𝑦0 + ℎ (𝑥0 𝑦0 2 − ) = 1 + 0.05 ((1 ∙ 12 ) − ) = 𝟏. 𝟎𝟎𝟎𝟎
𝑥0 1
𝑦 1.0000
𝑛 = 1: 𝑦2 ≈ 𝐿(𝑥2 ) = 𝑦1 + ℎ (𝑥1 𝑦1 2 − 𝑥1 ) = 1.0000 + 0.05 ((1.05 ∙ 1.00002 ) − 1.05
) =1.0049
1

𝑦 1.0049
𝑛 = 2: 𝑦3 ≈ 𝐿(𝑥3 ) = 𝑦2 + ℎ (𝑥2 𝑦2 2 − 𝑥2 ) = 1.0049 + 0.05 ((1.1 ∙ 1.00492 ) − 1.1
) =1.0147
2

The following tabulation was done using Excel:

Euler's Formula for h=0.05 Sample 1


𝒏 𝑥𝑛 𝑦𝑛 𝑦𝑛+1 𝑓 (𝑥𝑛 , 𝑦𝑛 )
0 1 1.0000 1.0000 0.0000
1 1.05 1.0000 1.0049 0.0976
2 1.1 1.0049 1.0147 0.1972
3 1.15 1.0147 1.0298 0.3018
4 1.2 1.0298 1.0506 0.4145
5 1.25 1.0506 1.0775 0.5391
6 1.3 1.0775 1.1115 0.6805
7 1.35 1.1115 1.1538 0.8446
8 1.4 1.1538 1.2057 1.0395
9 1.45 1.2057 1.2696 1.2765
10 1.5 1.2696 1.3481 1.5713
11 1.55 1.3481 1.4455 1.9473
12 1.6 1.4455 1.5675 2.4397
13 1.65 1.5675 1.7227 3.1041
14 1.7 1.7227 1.9243 4.0316
15 1.75 1.9243 2.1933 5.3803
16 1.8 2.1933 2.5653 7.4404
17 1.85 2.5653 3.1047 10.7878
18 1.9 3.1047 3.9387 16.6803
19 1.95 3.9387 5.3503 28.2313
20 2 5.3503 8.0791 54.5756

The approximation would improve if the value of h gets smaller and smaller. Another factor that
can affect the quality of approximation is the number of decimal places used. The more the decimal places
retained, it could be generalized that the better the approximation would be [1].
Improved Euler’s Method

One way to improve the approximations is to use an average slope of 𝑦𝑛 and 𝑦𝑛+1 . It normally
proceeds with using the Euler’s formula to compute for the initial approximation or estimate of
the y value, to be now called 𝑦 ∗ 𝑛+1 . Then the improved estimate would be calculated based on
the average slope between 𝑦𝑛 and 𝑦 ∗ 𝑛+1 [1].

𝒚∗ 𝒏+𝟏 ≈ 𝑳∗ (𝒙𝒏+𝟏 ) = 𝒚𝒏 + 𝒉𝒇(𝒙𝒏 , 𝒚𝒏 )

𝒇(𝒙𝒏 , 𝒚𝒏 ) + 𝒇(𝒙𝒏+𝟏 , 𝒚∗ 𝒏+𝟏 )


𝒚𝒏+𝟏 ≈ 𝑳(𝒙𝒏+𝟏 ) = 𝒚𝒏 + 𝒉
𝟐
The diagrams depict the improvement in the approximation of
the y values with the real values of the solution curve when the
Improved Euler’s method is used. The red dots represent the estimate
points obtained using Euler’s method, the blue dots represent the
estimate points using Improved Euler’s method, and the green dots
represent the real or actual point in the solution curve [1].

[1]

[4]
𝑑𝑦
Sample # 2: 𝑑𝑥 = 2𝑥 − 3𝑦 + 1 ; 𝑦(1) = 5

if ℎ = 0.05 𝑎𝑛𝑑 𝑢𝑝 𝑡𝑜 𝑛 = 20 𝑎𝑛𝑑 𝑠ℎ𝑜𝑤 𝑡ℎ𝑒 𝑟𝑒𝑙𝑎𝑡𝑖𝑣𝑒 𝑒𝑟𝑟𝑜𝑟 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 𝑎𝑐𝑡𝑢𝑎𝑙 𝑎𝑛𝑑 𝑒𝑠𝑡𝑖𝑚𝑎𝑡𝑒 𝑣𝑎𝑙𝑢𝑒𝑠
Sample Calculations:

𝑛 = 0:

𝑦 ∗1 ≈ 𝐿∗ (𝑥1 ) = 𝑦0 + ℎ(2𝑥0 − 3𝑦0 + 1) = 5 + 0.05((2 ∙ 1) − (3 ∙ 5) + 1) = 4.4000

(2𝑥0 − 3𝑦0 + 1) + (2𝑥1 − 3𝑦 ∗1 + 1)


𝑦1 ≈ 𝐿(𝑥1 ) = 𝑦0 + ℎ ( )
2
((2 ∙ 1) − (3 ∙ 5) + 1) + ((2 ∙ 1.05) − (3 ∙ 4.4000) + 1)
= 5 + 0.05 ( ) = 𝟒. 𝟒𝟒𝟕𝟓
2

n=1:

𝑦 ∗ 2 ≈ 𝐿∗ (𝑥2 ) = 𝑦1 + ℎ(2𝑥1 − 3𝑦1 + 1) = 4.4475 + 0.05((2 ∙ 1.05) − (3 ∙ 4.4475) + 1) = 3.9354

(2𝑥1 − 3𝑦1 + 1) + (2𝑥2 − 3𝑦 ∗ 2 + 1)


𝑦2 ≈ 𝐿(𝑥2 ) = 𝑦1 + ℎ ( )
2
((2 ∙ 1.05) − (3 ∙ 4.4475) + 1) + ((2 ∙ 1.10) − (3 ∙ 3.9354) + 1)
= 4.4475 + 0.05 ( )
2
= 𝟑. 𝟗𝟕𝟔𝟑
The following tabulation was done using Excel:

Improved Euler's Formula for h=0.05 Sample # 2



𝒏 𝒙𝒏 𝒚𝒏 𝒚 𝒏+𝟏
𝒚𝒏+𝟏 𝒇(𝒙𝒏 , 𝒚𝒏 ) 𝒇(𝒙𝒏+𝟏 , 𝒚𝒏+𝟏 ) 𝑨𝒗𝒈. 𝒇(𝒙𝒏 , 𝒚𝒏 )
0 1 5.0000 4.4000 4.4475 -12.0000 -10.1000 -11.0500
1 1.05 4.4475 3.9354 3.9763 -10.2425 -8.6061 -9.4243
2 1.1 3.9763 3.5398 3.5751 -8.7289 -7.3195 -8.0242
3 1.15 3.5751 3.2038 3.2342 -7.4252 -6.2114 -6.8183
4 1.2 3.2342 2.9190 2.9452 -6.3025 -5.2571 -5.7798
5 1.25 2.9452 2.6784 2.7009 -5.3355 -4.4352 -4.8853
6 1.3 2.7009 2.4758 2.4952 -4.5027 -3.7273 -4.1150
7 1.35 2.4952 2.3059 2.3226 -3.7855 -3.1176 -3.4515
8 1.4 2.3226 2.1642 2.1786 -3.1677 -2.5926 -2.8801
9 1.45 2.1786 2.0468 2.0592 -2.6357 -2.1403 -2.3880
10 1.5 2.0592 1.9503 1.9610 -2.1775 -1.7509 -1.9642
11 1.55 1.9610 1.8718 1.8810 -1.7829 -1.4154 -1.5992
12 1.6 1.8810 1.8088 1.8168 -1.4430 -1.1265 -1.2848
13 1.65 1.8168 1.7592 1.7661 -1.1503 -0.8777 -1.0140
14 1.7 1.7661 1.7212 1.7270 -0.8982 -0.6635 -0.7808
15 1.75 1.7270 1.6930 1.6980 -0.6811 -0.4789 -0.5800
16 1.8 1.6980 1.6733 1.6777 -0.4941 -0.3200 -0.4070
17 1.85 1.6777 1.6610 1.6648 -0.3330 -0.1831 -0.2580
18 1.9 1.6648 1.6551 1.6583 -0.1943 -0.0652 -0.1297
19 1.95 1.6583 1.6545 1.6573 -0.0748 0.0364 -0.0192
20 2 1.6573 1.6587 1.6611 0.0280 0.1238 0.0759

The given differential equation can be solved using analytical methods (method Linear 1st order). The
𝑑𝑦
solution curve for the D.E. 𝑑𝑥 = 2𝑥 − 3𝑦 + 1 at the given initial condition of 𝑦(1) = 1 is:

1 2 38
𝑦= + 𝑥 + 𝑒 3(1−𝑥)
9 3 9
With the given actual solution curve, the actual y values can be computed and compared with the
estimate values approximated by the Improved Euler’s method. The following tabulation was done using
Excel:

Comparison between Improved Euler's Method and the Actual Solution Curve
x Estimated y values Actual y values Absolute error % Relative error
1 5.0000 5.0000 0.0000 0.0000
1.05 4.4475 4.4452 0.0023 0.0515
1.1 3.9763 3.9723 0.0039 0.0992
1.15 3.5751 3.5700 0.0051 0.1426
1.2 3.2342 3.2283 0.0058 0.1810
1.25 2.9452 2.9389 0.0063 0.2140
1.3 2.7009 2.6944 0.0065 0.2411
1.35 2.4952 2.4886 0.0065 0.2622
1.4 2.3226 2.3162 0.0064 0.2772
1.45 2.1786 2.1723 0.0062 0.2863
1.5 2.0592 2.0532 0.0059 0.2898
1.55 1.9610 1.9553 0.0056 0.2882
1.6 1.8810 1.8757 0.0053 0.2822
1.65 1.8168 1.8118 0.0049 0.2725
1.7 1.7661 1.7615 0.0046 0.2598
1.75 1.7270 1.7228 0.0042 0.2451
1.8 1.6980 1.6941 0.0039 0.2289
1.85 1.6777 1.6741 0.0035 0.2119
1.9 1.6648 1.6615 0.0032 0.1946
1.95 1.6583 1.6553 0.0029 0.1775
2 1.6573 1.6547 0.0027 0.1610
Plot of the Estimated y values using improved Euler's method
superimposed with the actual solution curve
6.0000
y values

4.0000

2.0000

0.0000
1
1.05
1.1
1.15
1.2
1.25
1.3
1.35
1.4
1.45
1.5
1.55
1.6
1.65
1.7
1.75
1.8
1.85
1.9
1.95
2
x values

Improved Euler's method Actual Solution Curve

As a comparison, if the Euler’s method is used instead of the Improved Euler’s method, it can be
observed that the % relative errors are greater relative to the actual y values of the solution curve. This
signifies that the Improved Euler’s method is a better approximation than the Euler’s method. The
following tabulations were done using Excel:

Euler's Formula for h=0.05 Sample # 2


𝒏 𝒙𝒏 𝒚𝒏 𝒚𝒏+𝟏 𝒇(𝒙𝒏 , 𝒚𝒏 )
0 1 5.0000 4.4000 -12.0000
1 1.05 4.4000 3.8950 -10.1000
2 1.1 3.8950 3.4708 -8.4850
3 1.15 3.4708 3.1151 -7.1123
4 1.2 3.1151 2.8179 -5.9454
5 1.25 2.8179 2.5702 -4.9536
6 1.3 2.5702 2.3647 -4.1106
7 1.35 2.3647 2.1950 -3.3940
8 1.4 2.1950 2.0557 -2.7849
9 1.45 2.0557 1.9424 -2.2671
10 1.5 1.9424 1.8510 -1.8271
11 1.55 1.8510 1.7784 -1.4530
12 1.6 1.7784 1.7216 -1.1351
13 1.65 1.7216 1.6784 -0.8648
14 1.7 1.6784 1.6466 -0.6351
15 1.75 1.6466 1.6246 -0.4398
16 1.8 1.6246 1.6109 -0.2738
17 1.85 1.6109 1.6043 -0.1328
18 1.9 1.6043 1.6036 -0.0129
19 1.95 1.6036 1.6081 0.0891
20 2 1.6081 1.6169 0.1757

Comparison between Euler's Method and the Actual Solution Curve


x Estimated y values Actual y values Absolute error % Relative error
1 5.0000 5.0000 0.0000 0.0000
1.05 4.4000 4.4452 0.0452 1.0171
1.1 3.8950 3.9723 0.0773 1.9471
1.15 3.4708 3.5700 0.0992 2.7797
1.2 3.1151 3.2283 0.1132 3.5058
1.25 2.8179 2.9389 0.1210 4.1177
1.3 2.5702 2.6944 0.1242 4.6102
1.35 2.3647 2.4886 0.1240 4.9814
1.4 2.1950 2.3162 0.1212 5.2325
1.45 2.0557 2.1723 0.1166 5.3689
1.5 1.9424 2.0532 0.1109 5.3992
1.55 1.8510 1.9553 0.1043 5.3350
1.6 1.7784 1.8757 0.0974 5.1902
1.65 1.7216 1.8118 0.0902 4.9797
1.7 1.6784 1.7615 0.0831 4.7189
1.75 1.6466 1.7228 0.0762 4.4225
1.8 1.6246 1.6941 0.0695 4.1040
1.85 1.6109 1.6741 0.0632 3.7751
1.9 1.6043 1.6615 0.0572 3.4456
1.95 1.6036 1.6553 0.0517 3.1233
2 1.6081 1.6547 0.0466 2.8139

𝑑𝑦
Sample #3: 𝑑𝑥 = 𝑥 − 2𝑦 ; 𝑦(0) = 1 𝑖𝑓 ℎ = 0.10

a. Find y(2) using Euler’s and Improved Euler’s method (Hint: (2-0)/0.10 = 20; thus n=20)
b. The analytical solution is given as follows. Report the % relative errors for part a.

1 1 5
𝑦 = 𝑥 − + 𝑒 −2𝑥
2 4 4
Using Euler’s method:
Using Improved Euler’s method
Runge-Kutta Methods

It achieves the accuracy of a Taylor series method without the need of calculating higher-order
derivatives. It has the following general formula, where 𝜙(𝑥𝑖 , 𝑦𝑖 , ℎ ) is called the Increment function, 𝑝 and
𝑞 are constants, the 𝑘′𝑠 are recurrence relationships, and 𝑛 is the order. Euler’s method is actually a 1st-
order Runge-Kutta method. The 𝑘′𝑠 are slopes of the points, and so we are actually taking a weighted
average of the slopes, with the constants 𝑎𝑖 as the weighing factors [4].

𝑦𝑖+1 = 𝑦𝑖 + 𝜙(𝑥𝑖 , 𝑦𝑖 , ℎ )ℎ
𝜙 = 𝑎1 𝑘1 + 𝑎2 𝑘2 + ⋯ + 𝑎𝑛 𝑘𝑛

𝑘1 = 𝑓(𝑥𝑖 , 𝑦𝑖 )
𝑘2 = 𝑓(𝑥𝑖 + 𝑝1 ℎ, 𝑦𝑖 + 𝑞11 𝑘1 ℎ)
𝑘3 = 𝑓(𝑥𝑖 + 𝑝2 ℎ, 𝑦𝑖 + 𝑞21 𝑘1 ℎ + 𝑞22 𝑘2 ℎ)

𝑘𝑛 = 𝑓(𝑥𝑖 + 𝑝𝑛−1 ℎ, 𝑦𝑖 + 𝑞𝑛−1,1 𝑘1 ℎ + 𝑞𝑛−1,2 𝑘2 ℎ + 𝑞𝑛−1,3 𝑘3 ℎ + ⋯ + 𝑞𝑛−1,𝑛−1 𝑘𝑛−1 ℎ)

Second-order Runge-Kutta Methods

For n=2 Runge-Kutta methods, we have the following general set of relationships:

𝑦𝑖+1 = 𝑦𝑖 + (𝑎1 𝑘1 + 𝑎2 𝑘2 )ℎ; 𝑘1 = 𝑓 (𝑥𝑖 , 𝑦𝑖 ); 𝑘2 = 𝑓(𝑥𝑖 + 𝑝1 ℎ, 𝑦𝑖 + 𝑞11 𝑘1 ℎ)


There are 4 constants to be determined, 𝑎1 , 𝑎2 , 𝑝1 and 𝑞11 . As derived using Taylor-series
expansion, we have the following set of equations. Since there are 4 unknowns and only 3 available
equations, one of the constants must be specified. The constant to be specified is chosen to be 𝑎2 . Because
there are infinite possibilities for the value of 𝑎2 , there are infinite variations of the 2nd-order Runge-Kutta
methods. All of them yield the same exact results if the solution to the O.D.E is either a constant, a linear
or a quadratic. The three most common variations are listed below. The local truncation error is 𝑂(ℎ 3 )
[4].

𝑎1 + 𝑎2 = 1 → 𝑎1 = 1 − 𝑎2
1 1
𝑎2 𝑝1 = → 𝑝1 =
2 2𝑎2
1 1
𝑎2 𝑞11 = → 𝑞11 =
2 2𝑎2
Heun Method with a single corrector
1 1 1 1 1
𝑎2 = : 𝑎1 = 1 − = ; 𝑝1 = = 1; 𝑞11 = =1
2 2 2 1 1
2 (2) 2 (2)

𝟏 𝟏
𝒚𝒊+𝟏 = 𝒚𝒊 + ( 𝒌𝟏 + 𝒌𝟐 ) 𝒉
𝟐 𝟐
where:

𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 )
𝒌𝟐 = 𝒇(𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒌𝟏 𝒉)

Midpoint Method
1 1 1 1
𝑎2 = 1: 𝑎1 = 1 − 1 = 0; 𝑝1 = = ; 𝑞11 = =
2(1) 2 2(1) 2
𝒚𝒊+𝟏 = 𝒚𝒊 + (𝒌𝟐 )𝒉
where:

𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 )
𝟏 𝟏
𝒌𝟐 = 𝒇(𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒌𝟏 𝒉)
𝟐 𝟐

Ralston’s Method
2 2 1 1 3 1 3
𝑎2 = : 𝑎1 = 1 − = ; 𝑝1 = = ; 𝑞11 = =
3 3 3 2 2
2( ) 4 2( ) 4
3 3
1 2
𝒚𝒊+𝟏 = 𝒚𝒊 + ( 𝒌𝟏 + 𝒌𝟐 ) 𝒉
3 3
where:

𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 )
3 3
𝒌𝟐 = 𝒇(𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒌𝟏 𝒉)
4 4

Third-order Runge-Kutta Method

The same derivation for n=3 can be made, resulting into six equations with eight unknowns. The
local truncation error is 𝑂(ℎ 4 ). One common version is given below. It gives exact results for solutions
that are cubic, or for polynomials in which the O.D.E is cubic (and only x is the variable) such that the
solution is quadratic [4].
1
𝒚𝒊+𝟏 = 𝒚𝒊 + (𝒌𝟏 + 4𝒌𝟐 + 𝒌𝟑 )𝒉
6
where:

𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 )
1 1
𝒌𝟐 = 𝒇 (𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒌𝟏 𝒉)
2 2
𝒌𝟑 = 𝒇(𝒙𝒊 + 𝒉, 𝒚𝒊 − 𝒌𝟏 𝒉 + 𝟐𝒌𝟐 𝒉)

Fourth-order Runge-Kutta Method

The most preferred Runge-Kutta method is the fourth order. The most commonly used among
the variations is the Classical 4th order Runge-Kutta method or RK4 method [4].
1
𝒚𝒊+𝟏 = 𝒚𝒊 + (𝒌𝟏 + 2𝒌𝟐 + 2𝒌𝟑 + 𝒌𝟒 )𝒉
6
where:

𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 )
1 1
𝒌𝟐 = 𝒇 (𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒌𝟏 𝒉)
2 2
1 1
𝒌𝟑 = 𝒇 (𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒌𝟐 𝒉)
2 2
𝒌𝟒 = 𝒇(𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒌𝟑 𝒉)

Fifth-order Runge-Kutta method

The most recommended 5th order RK method is that of Butcher’s (1964), as given below. It is
somehow similar with that of the Boole’s rule [4].
1
𝒚𝒊+𝟏 = 𝒚𝒊 + (𝟕𝒌𝟏 + 32𝒌𝟑 + 12𝒌𝟒 + 𝟑𝟐𝒌𝟓 + 𝟕𝒌𝟔 )𝒉
90
where:

𝒌𝟏 = 𝒇(𝒙𝒊 , 𝒚𝒊 )
1 1
𝒌𝟐 = 𝒇 (𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒌𝟏 𝒉)
4 4
1 1 1
𝒌𝟑 = 𝒇 (𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒌𝟏 𝒉 + 𝒌𝟐 𝒉)
4 8 8
1 1
𝒌𝟒 = 𝒇 (𝒙𝒊 + 𝒉, 𝒚𝒊 − 𝒌𝟐 𝒉 + 𝒌𝟑 𝒉)
2 2
3 3 9
𝒌𝟓 = 𝒇 (𝒙𝒊 + 𝒉, 𝒚𝒊 + 𝒌𝟏 𝒉 + 𝒌𝟒 𝒉)
4 16 16
3 2 12 12 8
𝒌𝟔 = 𝒇 (𝒙𝒊 + 𝒉, 𝒚𝒊 − 𝒌𝟏 𝒉 + 𝒌𝟐 𝒉 + 𝒌𝟑 𝒉 − 𝒌𝟒 𝒉 + 𝒌𝟓 𝒉)
7 7 7 7 7

Sample #1: Solve the given initial value problem over the interval t=0 to 1 where y(0)=1 using the midpoint
method with h=0.50.
𝑑𝑦
= 𝑦𝑡 3 − 1.5𝑦
𝑑𝑡
𝑦𝑖+1 = 𝑦𝑖 + (𝑘2 )ℎ

where:
𝑘1 = 𝑓 (𝑡𝑖 , 𝑦𝑖 )
1 1
𝑘2 = 𝑓(𝑡𝑖 + ℎ, 𝑦𝑖 + 𝑘1 ℎ)
2 2

1st iteration: (i=0)


1 1 1 1
𝑡 = 0, 𝑦 = 1; 𝑡1 + ℎ = 0 + (0.50) = 0.25; 𝑦𝑖 + 𝑘1 = 1 + (−1.5)(0.50) = 0.625
2 2 2 2
𝑘1 = (1)(0)3 − 1.5(1) = −1.5
𝑘2 = (0.625)(0.25)3 − 1.5(0.625) = −0.9277
𝑦1 = 1 + (−0.3711)(0.5) = 𝟎. 𝟓𝟑𝟔𝟏

2nd iteration: (i=1)


1 1
𝑡 = 0.5, 𝑦 = 0.5361; 𝑡1 + ℎ = 0.5 + (0.50) = 0.75;
2 2
1 1
𝑦𝑖 + 𝑘1 = 0.5361 + (−0.7371)(0.50) = 0.3518
2 2

𝑘1 = (0.5361)(0.5)3 − 1.5(0.5361) = −0.7371


𝑘2 = (0.3518)(0.75)3 − 1.5(0.3518) = −0.3793
𝑦1 = 0.5361 + (−0.3793)(0.5) = 𝟎. 𝟑𝟒𝟔𝟓

3rd iteration: (i=2)


1 1
𝑡 = 1, 𝑦 = 0.3465; 𝑡1 + ℎ = 1 + (0.50) = 1.25;
2 2
1 1
𝑦𝑖 + 𝑘1 = 0.3465 + (−0.1733)(0.50) = 0.3032
2 2
𝑘1 = (0.3465)(1)3 − 1.5(0.3465) = −0.1733
𝑘2 = (0.3032)(1.25)3 − 1.5(0.3032) = 0.1374
𝑦1 = 𝟎. 𝟑𝟒𝟔𝟓 + (0.1374)(0.5) = 𝟎. 𝟒𝟏𝟓𝟐

Sample #2: Find y(1.5) of the solution curve for the given O.D.E with h=0.1 using the method listed below.
The initial condition is y(1)=1.
𝑑𝑦 𝑦
= (𝑥𝑦)2 −
𝑑𝑥 𝑥

a. 1st order Runge-Kutta method

b. Heun’s method
c. Midpoint method

d. Ralston’s method
e. 3rd order Runge Kutta method

f. Classical 4th order Runge Kutta method


g. Butcher’s 5th order Runge Kutta method

Sample #3: A spherical tank has a circular orifice in its bottom through which the liquid flows out (Fig.
P25.20). The flow rate through the hole can be estimated with the given equation, where Qout = outflow
(m3/s), C = an empirically-derived coefficient, A = the area of the orifice (m2), g = the gravitational constant
(= 9.81 m/s2), and H = the depth of liquid in the tank. Use one of the numerical methods described in this
chapter to determine how long it will take for the water to flow out of a 3-m diameter tank with an initial
height of 2.75 m. Note that the orifice has a diameter of 3 cm and C = 0.55.
𝑑𝑉
𝑄𝑜𝑢𝑡 = = 𝐶𝐴√2𝑔𝐻
𝑑𝑡
𝑡0 = 0 𝑚 𝑎𝑛𝑑 𝐻 = 2.75 𝑚 → 𝐻 (0) = 2.75 𝑚 (𝑖𝑛𝑖𝑡𝑖𝑎𝑙 𝑐𝑜𝑛𝑑𝑖𝑡𝑖𝑜𝑛)

𝑑 2 0.03 2
𝐴 = 𝜋( ) = 𝜋( ) = 2.25 × 10−4 𝜋
2 2
-We have the following relationship between V and H of a sphere:

𝜋𝐻2 (3𝑟 − 𝐻) 𝑑𝑉 6𝜋𝑟𝐻


𝑉= → = − 𝜋𝐻2 = 2𝜋𝑟𝐻 − 𝜋𝐻2 → 𝑑𝑉 = (2𝜋𝑟𝐻 − 𝜋𝐻2 )𝑑𝐻
3 𝑑𝐻 3
(2𝜋𝑟𝐻 − 𝜋𝐻2 )𝑑𝐻 𝑑𝐻 𝐶𝐴√2𝑔𝐻 0.55(2.25 × 10−4 𝜋)√2(9.81)𝐻
𝑄𝑜𝑢𝑡 = = 𝐶𝐴√2𝑔𝐻 → = =
𝑑𝑡 𝑑𝑡 (2𝜋𝑟𝐻 − 𝜋𝐻2 ) (2𝜋 ∙ 1.5𝐻 − 𝜋𝐻2 )

𝑑𝐻 (1.2375 × 10−4 )√19.62𝐻 𝑑𝐻 (1.2375 × 10−4 )√19.62𝐻


→ = → = − ; 𝑑𝑒𝑐𝑟𝑒𝑎𝑠𝑖𝑛𝑔 𝐻 𝑎𝑠 𝑡 ↑
𝑑𝑡 (3𝐻 − 𝐻2 ) 𝑑𝑡 (3𝐻 − 𝐻2 )
-We use the 5th order RK method with h=50 to evaluate from 2.75 m to 0 m:
-The spherical tank would be emptied between 7450 and 7500 sec. Better results would be obtained if
smaller increments would be used. Below is a summary of the results when the increment size is
changed:

ℎ = 25: 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 7475 𝑎𝑛𝑑 7500 𝑠𝑒𝑐.

ℎ = 10: 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 7475 𝑎𝑛𝑑 7500 𝑠𝑒𝑐.


ℎ = 10: 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 7480 𝑎𝑛𝑑 7490 𝑠𝑒𝑐.
ℎ = 5: 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 7485 𝑎𝑛𝑑 7490 𝑠𝑒𝑐.

ℎ = 10: 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 7480 𝑎𝑛𝑑 7490 𝑠𝑒𝑐.


ℎ = 1: 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 7488 𝑎𝑛𝑑 7489 𝑠𝑒𝑐.
ℎ = 0.5: 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 7487.5 𝑎𝑛𝑑 7488 𝑠𝑒𝑐.
𝒉 = 𝟎. 𝟏: 𝒃𝒆𝒕𝒘𝒆𝒆𝒏 𝟕𝟒𝟖𝟕. 𝟔 𝒂𝒏𝒅 𝟕𝟒𝟖𝟕. 𝟕 𝒔𝒆𝒄.

References:

[1] Zill, D. and Cullen, M. Differential Equations with Boundary-value Problems. 7th ed. Cengage Lea
rning, 2009.
[2] Available online at https://www.geogebra.org/m/m9TKgYVh
[3] Available online at https://guide.freecodecamp.org/mathematics/differential-equations/eulers-meth
od/
[4] Available online at https://www.geogebra.org/materials
[5] Chapra, S. C., & Canale, R. P. (2010). Numerical methods for engineers: with software and
programming applications (6th ed.). Boston: McGraw-Hill.

The Matlab codes used in the examples are available online:

Robby Ching (2020). Numerical methods in solving 1st order ODEs


(https://www.mathworks.com/matlabcentral/fileexchange/77717-numerical-methods-in-solving-1st-
order-odes), MATLAB Central File Exchange. Retrieved July 3, 2020.

You might also like