Docsity

Numerical methods in solving 1st order ODEs, Study notes of Advanced Calculus

Toggle sidebar
bg1
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].
𝑑𝑦
𝑑𝑥= 𝑥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 𝑎𝑡 𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡 𝑦
𝑦↑= 𝑦 𝑣𝑎𝑙𝑢𝑒 𝑎𝑏𝑜𝑣𝑒 𝑦0 𝑎𝑡 𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡 𝑥
𝑦↓= 𝑦 𝑣𝑎𝑙𝑢𝑒 𝑏𝑒𝑙𝑜𝑤 𝑦0 𝑎𝑡 𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡 𝑥
a. (1st Quadrant) 𝑥0=𝑦0
• 𝑥→ ; 𝑑𝑦
𝑑𝑥 =+
• 𝑥← ; 𝑑𝑦
𝑑𝑥 =−
• 𝑦↑ ; 𝑑𝑦
𝑑𝑥 =−
• 𝑦↓ ; 𝑑𝑦
𝑑𝑥 =+
b. (2nd Quadrant) −𝑥0=𝑦0
• 𝑥→ ; 𝑑𝑦
𝑑𝑥 =−
• 𝑥← ; 𝑑𝑦
𝑑𝑥 =+
• 𝑦↑ ; 𝑑𝑦
𝑑𝑥 =−
• 𝑦↓ ; 𝑑𝑦
𝑑𝑥 =+
𝑑𝑦
𝑑𝑥 = 0 would give a horizontal lineal
element. From the given D.E., it can be seen
that as long as x and y values are the same, it
would give 𝑑𝑦
𝑑𝑥 =0. This is bracketed in the
direction field.
[1]
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19

Partial preview of the text

Download Numerical methods in solving 1st order ODEs and more Study notes Advanced Calculus in PDF only on Docsity!

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 1

st

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].

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

↓

0

a. (

st

Quadrant) 𝑥

0

0

→

𝑑𝑦

𝑑𝑥

←

𝑑𝑦

𝑑𝑥

↑

𝑑𝑦

𝑑𝑥

↓

𝑑𝑦

𝑑𝑥

b. ( 2

nd

Quadrant) −𝑥

0

0

→

𝑑𝑦

𝑑𝑥

←

𝑑𝑦

𝑑𝑥

↑

𝑑𝑦

𝑑𝑥

↓

𝑑𝑦

𝑑𝑥

𝑑𝑦

𝑑𝑥

= 0 would give a horizontal lineal

element. From the given D.E., it can be seen

that as long as x and y values are the same, it

would give

𝑑𝑦

𝑑𝑥

= 0. This is bracketed in the

direction field.

[1]

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 1

st

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].

Suppose we have the following initial conditions:

a. 𝑦

= 1 : Green curve

b. 𝑦

= 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].

𝒅𝒚

𝒅𝒙

→ 𝒚 = 𝟎; ln

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

c. (

rd

Quadrant) −𝑥

0

0

→

𝑑𝑦

𝑑𝑥

←

𝑑𝑦

𝑑𝑥

↑

𝑑𝑦

𝑑𝑥

↓

𝑑𝑦

𝑑𝑥

d. (

th

Quadrant) −𝑥

0

0

→

𝑑𝑦

𝑑𝑥

←

𝑑𝑦

𝑑𝑥

↑

𝑑𝑦

𝑑𝑥

↓

𝑑𝑦

𝑑𝑥

[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

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].

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].

[2]

[2]

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 1

st

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 1

st

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

𝟎

. 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]:

𝟏

1

0

0

0

𝟐

2

1

1

1

y

3

≈L

x

3

=y

2

+hf

x

2

,y

2

𝒏+𝟏

𝒏+𝟏

𝒏

𝒏

𝒏

[3]

[1]

2

2

1

1

1

2

𝑦

1

𝑥

1

2

  1. 0000

  2. 05

3

3

2

2

2

2

𝑦

2

𝑥

2

2

  1. 0049

  2. 1

The following tabulation was done using Excel:

Euler's Formula for h=0.05 Sample 1

𝑛

𝑛

𝑛+ 1

𝑛

𝑛

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].

[4]

[1]

The given differential equation can be solved using analytical methods (method Linear 1

st

order). The

solution curve for the D.E.

𝑑𝑦

𝑑𝑥

= 2 𝑥 − 3 𝑦 + 1 at the given initial condition of 𝑦

= 1 is:

3 ( 1 −𝑥)

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

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

𝒏

𝒏

𝒏+𝟏

𝒏

𝒏

1

2

y values

x values

Plot of the Estimated y values using improved Euler's method

superimposed with the actual solution curve

Improved Euler's method Actual Solution Curve

Using Euler’s method:

Using Improved Euler’s method

Heun Method with a single corrector

2

1

1

11

𝒊+𝟏

𝒊

𝟏

𝟐

where:

𝟏

𝒊

𝒊

𝟐

𝒊

𝒊

𝟏

Midpoint Method

2

1

1

11

𝒊+𝟏

𝒊

𝟐

where:

𝟏

𝒊

𝒊

𝟐

𝒊

𝒊

𝟏

Ralston’s Method

2

1

1

11

𝒊+𝟏

𝒊

𝟏

𝟐

where:

𝟏

𝒊

𝒊

𝟐

𝒊

𝒊

𝟏

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].

𝒊+𝟏

𝒊

𝟏

𝟐

𝟑

where:

𝟏

𝒊

𝒊

𝟐

𝒊

𝒊

𝟏

𝟑

𝒊

𝒊

𝟏

𝟐

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 4

th

order Runge-Kutta method or RK4 method [4].

𝒊+𝟏

𝒊

𝟏

𝟐

𝟑

𝟒

where:

𝟏

𝒊

𝒊

𝟐

𝒊

𝒊

𝟏

𝟑

𝒊

𝒊

𝟐

𝟒

𝒊

𝒊

𝟑

Fifth-order Runge-Kutta method

The most recommended 5

th

order RK method is that of Butcher’s (1964), as given below. It is

somehow similar with that of the Boole’s rule [4].

𝒊+𝟏

𝒊

𝟏

𝟑

𝟒

𝟓

𝟔

where:

𝟏

𝒊

𝒊

𝟐

𝒊

𝒊

𝟏

1

3

2

3

1

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. 1

st

order Runge-Kutta method

b. Heun’s method

c. Midpoint method

d. Ralston’s method