0% found this document useful (0 votes)
15 views13 pages

CSU 07320 Lecture 4-Numerical methods for ODE

The document discusses numerical methods for solving ordinary differential equations, focusing on Euler's method and its modified version. It explains the limitations of Euler's method and provides examples of its application, including a comparison with exact solutions. Additionally, it introduces the modified Euler method for improved accuracy and presents exercises for practice.

Uploaded by

Craig Calvin
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)
15 views13 pages

CSU 07320 Lecture 4-Numerical methods for ODE

The document discusses numerical methods for solving ordinary differential equations, focusing on Euler's method and its modified version. It explains the limitations of Euler's method and provides examples of its application, including a comparison with exact solutions. Additionally, it introduces the modified Euler method for improved accuracy and presents exercises for practice.

Uploaded by

Craig Calvin
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/ 13

CSU 07320: COMPUTING MATHEMATICS

Lecture 4: Numerical Methods for Ordinary Differential Equations

January 10, 2023

January 10, 2023 1 / 13


Introduction

Many problems in science and engineering can be reduced to the problem of solving differential
equations satisfying certain given conditions.

The analytical methods of solutions, with which you (students) are assumed to be familiar,
can be applied to solve only a selected class of differential equations.

Those equations which goven physical systems do not possess, in general closed form solutions,
and hence recourse must be made to numerical methods for solving such differential equations.

January 10, 2023 2 / 13


To describe various numerical methods for solution of ordinary differential equations, we
consider the general first order differential equation
dy
= f (x, y ) (1)
dx
with the initial condition,
y (x0 ) = y0 (2)
and illustrate the theory with respect to this equation.

January 10, 2023 3 / 13


Euler’s Method
Consider an ordinary differential equation

y 0 = f (x, y ), y (x0 ) = y0 . (3)

Solving the equation (3) for values of y at x = xr = x0 + rh, r = 1, 2, . . . we have to integrate


(3) as follows:
Z x1 Z x1
y 0 dx = f (x, y ) dx, x0 ≤ x ≤ x1
x0 x0
Z x1
x1
[y (x)]x0 = f (x, y ) dx
x0
Z x1
y (x1 ) − y (x0 ) = f (x, y ) dx
x0
Z x1
y (x1 ) = y (x0 ) + f (x, y ) dx (4)
x0

January 10, 2023 4 / 13


Assuming f (x, y ) = f (x0 , y0 ) in x0 ≤ x ≤ x1 , we find that,
Z x1
y1 ≈ y0 + f (x0 , y0 ) dx
x0
y1 ≈ y0 + (x1 − x0 )f (x0 , y0 )
⇒ y1 ≈ y0 + hf (x0 , y0 ). (5)

Similarly for the range x1 ≤ x ≤ x2 , we have


Z x2
y2 = y1 + f (x, y ) dx. (6)
x1

Substituting f (x1 , y1 ) for f (x, y ) in x1 ≤ x ≤ x2 , we obtain

y2 ≈ y1 + hf (x1 , y1 ). (7)

For subsequent iterations, the Euler’s method requires that,

yn+1 = yn + hf (xn , yn ), n = 0, 1, 2, . . . (8)

January 10, 2023 5 / 13


The process is very slow and to obtain reasonable accuracy with Euler’s method, we need to
take a smaller value for h.

Because of this restriction on h, the method is unsuitable for practical use and a modification
of it, known as the modified Euler method, which gives more accurate results, is also described
in this lecture.

January 10, 2023 6 / 13


Example
Use Euler’s method to find y (0.04) given that y satisfies the differential equation

dy + ydx = 0; y (0) = 1.

Compare your answer with exact solution. Use h = 0.01.


Solution: The given differential equation can be written as
dy
= −y or y 0 = −y
dx
or
f (x, y ) = −y .

January 10, 2023 7 / 13


Example
This implies that, successive application of eqn. (8) with h = 0.01 gives

y1 = y (0.01) = y0 + hf (x0 , y0 )
= 1 + 0.01(−1) = 0.99
y2 = y (0.02) = y1 + hf (x1 , y1 )
= 0.99 + 0.01(−0.99) = 0.9801
y3 = y (0.03) = y2 + hf (x2 , y2 )
= 0.9801 + 0.01(−0.9801) = 0.9703
y4 = y (0.04) = y3 + hf (x3 , y3 )
= 0.9703 + 0.01(−0.9703) = 0.9606.

The exact solution of the given d.e. is y = e −x , and from this, the value at x = 0.04 is 0.9608.

January 10, 2023 8 / 13


Modified Euler’s Method
From Euler formula, Z x1
y1 = y0 + f (x, y ) dx, (9)
x0
we approximate an integral in (9) by means of trapezoidal rule. This gives
h
y1 = y0 + [f (x0 , y0 ) + f (x1 , y1 )], (10)
2
from which we obtain iterations formula
(n+1) hh (n)
i
y1 = y0 + f (x0 , y0 ) + f (x1 , y1 ) , n = 0, 1, 2, . . . (11)
2
(n)
where y1 is the nth approximation to y1 . The iteration formula (11) can be started by
(0)
choosing y1 from Euler’s formula:
(0)
y1 = y0 + hf (x0 , y0 ). (12)

January 10, 2023 9 / 13


Example
Determine the value of y when x = 0.1 given that y (0) = 1 and y 0 = x 2 + y . Take h = 0.05.
Solution:
We write the given ode in the form

f (x, y ) = x 2 + y , x0 = 0, y0 = 1.
(0)
Use improved (modified) Euler’s method. Now y1 can be obtained from Euler’s formula:
(0)
y1 = y0 + hf (x0 , y0 )
= 1 + 0.05 × f (0, 1) = 1 + 0.05(1) = 1.05.

Since x0 = 0, then x1 = x0 + h = 0.05. It follows that, using the modified Euler’s formula
(11),

(1) h (0) 0.05


y1 = y0 + [f (x0 , y0 ) + f (x1 , y1 )] = 1 + [1 + f (0.05, 1.05)] = 1.0513.
2 2
January 10, 2023 10 / 13
Example

(2) h (1)
y1 = y0 + [f (x0 , y0 ) + f (x1 , y1 )]
2
0.05
= 1+ [1 + f (0.05, 1.0513)] = 1.0513.
2
(n)
Stop the iterations when y1 repeats itself, and that will be the value of y corresponding to
the value of x. That is,
y (0.05) = 1.0513.
(n)
Next we find y2 . Using the basic Euler’s method, we have
(0)
y2 = y1 + hf (x1 , y1 ) = 1.0513 + f (0.05, 1.0513)
= 1.10399
≈ 1.1040.

January 10, 2023 11 / 13


Example
Since x1 = 0.05, then x2 = x1 + h = 0.05 + 0.05 = 0.1. It follows that, using the modified
Euler’s formula (11),

(1) h (0)
y2 = y1 + [f (x1 , y1 ) + f (x2 , y2 )]
2
0.05
= 1.0513 + [f (0.05, 1.0513) + f (0.1, 1.1040)] = 1.1055.
2
(2) h (1)
y2 = y1 + [f (x1 , y1 ) + f (x2 , y2 )]
2
0.05
= 1.0513 + [1.0538 + f (0.1, 1.1055)] = 1.1055.
2
⇒ y (0.1) = 1.1055.

Hence, we conclude that the value of y when x = 0.1 is 1.1055.

January 10, 2023 12 / 13


Exercises

Z 1
1
1 Evaluate I = dx correct to 3 decimal places with 8 strips (n = 8) by using
0 1+x
(a) trapezoidal rule and
(b) Simpson’s 1/3 rule.
Compare with the exact solution and state which method gives the best approximation
and why?
dy
2 Given that = x 2 + y , y (0) = 1, determine y (0.02), y (0.04) and y (0.06) using Euler’s
dx
modified method.

January 10, 2023 13 / 13

You might also like