3.4 Numerical Solution of Differential Equations

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 21

3.

4 Numerical Solution of
Differential equations

In this part, we discuss two numerical methods to


compute approximate solutions of differential equations:
1) One-step Euler method
2) The fourth order Runge-Kutta method

NOTATION
Usually, the differential operation is denoted by
dy
y ' or
dx
In this part, we also use this notation as a
function in x and y, i.e.
dy
y ' f ( x, y ).
dx
2

3.4.1 One-step Euler Method

This method is the most basic numerical


method used to solve differential equation.
We shall discuss this Euler Method using the
following example:

See the following figure


y
4

(x1, y1)

(x0, y0)

Figure 3.9 One-step Euler Method with h = 1.


4

We know that the gradient of the tangent line


dy
of a curve is given by y ' .
dx
In the previous figure, we assume that y1
is the approximation of the value of y.

Putting the gradient equation and the gradient


of the tangent line together, we have
y1 y0 y1 y0
y0 '

x1 x0
h

y1 y0 hy0 '

where y0 ' is the gradient of the tangent line at ( x0 , y0 ),


and h x1 x0 is the length of the considered subinterval.

See the following figure:

(x, y)

(x, y)
1

(x, y)

1.5

Figure 3.10 One-step Euler Method with h 0.5.


7

Notice that in general, the formula we use to


estimate y can be written as

yi 1 yi hy1 '
The formula of One-step Euler Method

NOTATION
The values of x to be considered can be denoted by
x a (h)b.
This notation means that we begin with x a and
add up h to the value of x in every calculation
of subinterval until reaching the last value at x b.

Example 3.14
x 1(0.2)3
Values of x are
x 1 , x 1.2, x 1 .4,, x 2.8, x 3.
x 1(0.2)3
Values of x are
x 1 , x 1.2, x 1 .4, , x 2.8, x 3.

Example 3.15
Suppose we take five subintervals to solve
dy
our previous problem , i.e. given
x(2 x) y
dx
passing through (1,1) , approximat e y at x 2.

Solution
Here,
and

2 1
h
5
0.2.
x 1(0.2)2.

10

The results of our approximation are listed in the


following table:

xi

yi

yi

1.0

1.2

1.4

2.36

1.4

1.872

2.712

1.6

2.4144

3.0544

1.8

3.02528

3.38528

2.0

3.702336

Approximation by One-step Euler method with h 0.2.


11

If we take ten subintervals, we have


i

xi

yi

yi

1.0

1.1

1.2

2.19

1.2

1.419

2.379

1.3

1.6569

2.5669

1.4

1.91359

2.75359

1.5

2.188949

2.938949

1.6

2.482844

3.122844

1.7

2.795128

3.305128

1.8

3.125641

3.485641

1.9

3.474205

3.664205

10

2.0

3.840626

Approximation by One-step Euler method with h 0.1.

12

3.4.2 : The fourth order Runge-Kutta


Method

Runge-Kutta Method is more accurate


compare to Euler Method.
As usual, given y f (x, y) and the initial
condition (x0, y0) and we want to find the
value of y at other values of x.

13

In Runge - Kutta Method, we need to calculate


four intermediate values as follows :
k1 hf ( xi , yi )

h
k1
k 2 hf xi , yi
2
2

h
k2

k3 hf xi , yi
2
2

k 4 hf ( xi h, yi k3 )
where h xi 1 xi
and

1
yi 1 yi (k1 2k 2 2k3 k 4 ).
6
14

Example 3.16
dy
x(2 x) y passing through (1,1).
dx
Approximat e the value of y for x 1(0.5)2.

Given

Solution
In this example we have x0 1, x1 1.5, x2 2.
To estimate y at x1 1.5, we calculate
the following four intermediate values. Using
( x0 , y0 ) (1,1), we have
15

k1 hf ( x0 , y0 )
(0.5) f (1, 1)
(0.5)[1( 2 1) 1] 1

h
k1
k2 hf x0 , y0
2
2

(0.5) f (1.25, 1.5)


(0.5)[1.25( 2 1.25) 1.5]
1.21875
h
k

k3 hf x0 , y0 2
2
2

(0.5) f (1.25, 1.609375)


(0.5)[1.25( 2 1.25) 1.609375]
1.273438.
16

k 4 hf ( x0 h, y0 k3 )

and

(0.5) f (1.5, 2.273438)


(0.5)[1.5(2 1.5) 2.273438]
1.511719
1
y1 y0 (k1 2k 2 2k3 k 4 )
6
1
1 (1 2(1.21875) 2(1.273438) 1.511719 )
6
2.249349.

Result : y1 2.249349 at x1 1.5.


17

To compute y at x2 2, we repeat our previous


calculation, but now using ( x1 , y1 ) (1.5, 2.249349).
We have
k1 hf ( x1 , y1 )
(0.5) f (1.5, 2.249349)
(0.5)[1.5(2 1.5) 2.249349]
1.499674
h
k

k 2 hf x1 , y1 1
2
2

0.5
1.499674

(0.5) f 1.5
,2.249349

2
2

(0.5) f (1.75, 2.999186)


(0.5)[1.75(2 1.75) 2.999186]
1.718343.

18

h
k2
k3 hf x1 , y1
2
2

0.5
1.718343

(0.5) f 1.5
,2.249349

2
2

(0.5) f (1.75, 3.108521)


(0.5)[1.75( 2 1.75) 3.108521]
1.773010

k4 hf ( x1 h, y1 k3 )
(0.5) f (1.5 0.5, 2.249349 1.773010)
(0.5) f ( 2, 4.022359)
(0.5) f [2( 2 2) 4.022359]
2.011180 .
19

and

1
y2 y1 (k1 2k 2 2k3 k 4 )
6
3.998276.

Result : y2 3.998276 when x2 2.


See the following table for the result of our calculation :
i

xi

yi

k1

k2

1.21875

1.5

2.249349

3.998276

k3

k4

1.273438 1.511719

1.499674 1.718383 1.773010 2.011180


-

20

If we take five subintervals, i.e. x 1(0.2) 2,


we have y 3.999948 at x 2.
If we continue, by taking ten subintervals,
i.e. x 1(0.1)2, we obtain y 3.999997 at x 2.

Conclusion
If we increase the number of subintervals
(i.e. with smaller value of h),
then we obtain a more accurate approximation
21

You might also like