0% found this document useful (0 votes)
26 views41 pages

+++unit 3 - Numerical Solution Techniques For ODEs

The document discusses numerical methods for solving ordinary differential equations (ODEs). It introduces the idea of approximating derivatives using finite differences and the forward difference approximation derived from Taylor's theorem. Euler's method and higher-order Runge-Kutta methods are presented as single-step numerical methods for solving ODEs. Examples are provided to demonstrate applying Euler's method to approximate solutions and compare to exact solutions.

Uploaded by

basheribrahim47
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views41 pages

+++unit 3 - Numerical Solution Techniques For ODEs

The document discusses numerical methods for solving ordinary differential equations (ODEs). It introduces the idea of approximating derivatives using finite differences and the forward difference approximation derived from Taylor's theorem. Euler's method and higher-order Runge-Kutta methods are presented as single-step numerical methods for solving ODEs. Examples are provided to demonstrate applying Euler's method to approximate solutions and compare to exact solutions.

Uploaded by

basheribrahim47
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 41

AECH4102 - Applied Differential Equations

Unit 3 - Numerical Solution Techniques for ODEs


www.udst.edu.q
Numerical Solution to ODEs
• In general, only simple (linear) ODEs can be solved
analytically

• Most interesting ODEs are nonlinear, must solve


numerically

• The idea is to approximate the derivatives by


subtraction

• Numerical methods for ordinary differential


equations calculate solution on the points
𝒙 𝒊+𝟏=,where
𝒙 𝒊 + 𝜟 𝒙 Δ𝑥 is the steps size

2
Derive the forward difference
approximation from Taylor series
Taylor’s theorem says that if you know the value of a function ' f ' at a point
xi and all its derivatives at that point, provided the derivatives are

continuous between xi and xi 1 , then


f xi 
f xi 1   f xi   f xi xi 1  xi   xi 1  xi 2  
2!

Substituting for convenience Δx  xi 1  xi

f xi 
f xi 1   f xi   f xi Δx  Δx 2  
2!

f xi 1   f xi  f xi 


f xi    x   
x 2!

f xi 1   f xi 
f xi    0x 
x 3
Forward Difference Approximation

limf x  Δx   f x 
f x  
Δx  0 Δx

For a finite ' Δx'

f x  x   f x 
f x  
x

*
4
Graphical Representation Of Forward Difference
Approximation

f(x)

x x+Δx

Figure: Graphical Representation of forward difference approximation of first derivative.

5
Example 1:
The velocity of a rocket is given by

 14  10 4 
 t   2000 ln    9.8t ,0  t  30
14  10  2100t 
4

where 'ν' is given in m/s and 't ' is given in seconds.

a) Use forward difference approximation of the first derivative of νt  to


calculate the acceleration at t  16s . Use a step size of Δt  2 s .

6
Solution  14  10 4 
 18  2000 ln    9.818
 14  10 4
 2100 18 
 453.02m/s

 14  10 4 
 16  2000 ln    9.816 
 ti 1   ti  14  10  210016 
4
ati  
t  392.07m/s
Hence
ti  16
 18  16 
a16  
Δt  2 2

453.02  392.07
ti 1  ti  t 
2
 16  2
 18  30.474m/s 2

 18  16
a16  The exact value of a 16 ?
2
7
Finite Difference Approximation of Higher Derivatives

One can use Taylor series to approximate a higher order derivative.


For example, to approximate f x  , the Taylor series for

f xi   
f xi  2   f xi   f xi 2Δx   2Δx 2  f xi 2Δx 3  
2! 3!
where

xi  2  xi  2Δx

f xi   
f xi 1   f xi   f xi x   x 2  f xi x 3 
2! 3!
where

𝑥𝑖+1 =𝑥 𝑖 + Δ 𝑥
8
Finite Difference Approximation of Higher Derivatives Cont.

Subtracting 2 times equation (4) from equation (3) gives

f xi  2   2 f xi 1    f xi   f xi Δx   f xi Δx  


2 3

f xi  2   2 f xi 1   f xi 


f xi    f xi Δx   
Δx  2

f xi  2   2 f xi 1   f xi 


f xi    0Δx  (5)
Δx  2

9
Classification of the Methods
Numerical Methods
for Solving ODE

Single-Step Methods Multiple-Step Methods

Estimates of the solution Estimates of the solution


at a particular step are at a particular step are
entirely based on based on information on
information on the more than one step
previous step

10
Numerical Methods for ODE
• Euler Methods
– Forward Euler Methods
– Backward Euler Method
– Modified Euler Method

• Runge-Kutta Methods
– Second Order
– Third Order
– Fourth Order

11
(I) Euler’s Method
𝑑𝑦
yi 1  yi  f xi , yi h
= 𝑓 ( 𝑥 , 𝑦 ) , 𝑦 ( 0) =𝑦0
𝑑𝑥

y1  y 0  f x0 , y 0 x1  x0 
h  xi 1  xi
 y0  f x0 , y0 h

Figure: General graphical interpretation of Euler’s method 12


How to write Ordinary Differential Equation?
dy
How does one write a first order differential equation in the form of  f x , y 
dx

Example 2:

dy
 2 y  1.3e  x , y 0   5
dx

is rewritten as

dy
 1.3e  x  2 y, y 0   5
dx

In this case

f x, y   1.3e  x  2 y

13
Example 3:Compare with exact sol
dy
  y , y ( 0)  1
dx

f ( x, y )   y, f (0,1)  1
Choose x  0.1
y (0.1)  y (0)  (1)  0.1  1  0.1  0.9
y (0.2)  y (0.1)  (0.9)  0.1  0.9  0.09  0.81
y (0.3)  y (0.2)  (0.81)  0.1  0.81  0.081  0.729

14
Example (cont)

y
1

Exact Solution :
dy
 y
 dx

 ln y   x  c
 y=e–x
y  ce  x y ( 0)  c   1
 y  ex
x

0.1

15
Example 4: solve
y '  ty  1, y0  y (0)  1, 0  t  1, h  0.25
Solution:
for t0  0, y0  y (0)  1

for t1  0.25, y1  y0  hy0 '


 y0  h(t0 y0  1)
 1  0.25(0 *1  1)  1.25

for t 2  0.5, y2  y1  hy1 '


 y1  h(t1 y1  1)
 1.25  0.25(0.25 *1.25  1)  1.5781
etc
16
Example 5:
A ball at 1200K is allowed to cool down in air at an ambient temperature of 300K.
Assuming heat is lost only due to radiation, the differential equation for the temperature of
the ball is given by

d
dt
 
 2.2067  10 12  4  81 108 ,  0   1200 K

Find the temperature at t  480 seconds using Euler’s method. Assume a step size of

h  240 seconds.

17
Solution
Step 1:
d
dt

 2.2067  10 12  4  81  10 8 

f t ,   2.2067  10 12  4  81 10 8 

 i 1   i  f ti ,  i h
1   0  f t0 ,  0 h
 1200  f 0,1200 240
  
 1200   2.2067  10 12 1200 4  81 108 240
 1200   4.5579 240
 106.09 K

1 is the approximate temperature at t  t1  t0  h  0  240  240


 240  1  106.09 K
18
Solution Cont.
Step 2: For i  1, t1  240, 1  106.09

 2  1  f t1 , 1 h
 106.09  f 240,106.09 240
 
 106.09   2.2067  10 12 106.09 4  81 108 240
 106.09  0.017595240
 110 .32 K

 2 is the approximate temperature at t  t 2  t1  h  240  240  480


 480   2  110 .32 K

19
Solution Cont.
The exact solution of the ordinary differential equation is given by the
solution of a non-linear equation as
  300
0.92593 ln  1.8519 tan 1 0.00333   0.22067 10 3 t  2.9282
  300
The solution to this nonlinear equation at t=480 seconds is  (480)  647.57 K

Comparison of Exact and Numerical Solutions:

20
Effect of step size?
Table: Temperature at 480 seconds as a function of step size, h

Step, h q(480) Et |єt|%

480 −987.81 1635.4 252.54


240 110.32 537.26 82.964
120 546.77 100.80 15.566
60 614.97 32.607 5.0352
30 632.77 14.806 2.2864

 (480)  647.57 K (exact)

21
Exercise 1:

22
Exercise 2

Solution 1

23
Exercise 2 (Cont’d)

Continue Solution 1

24
Exercise 2 (Cont’d)

Solution 2

25
Exercise 2 (Cont’d)

Continue Solution 2

26
Runge – Kutta Methods
• Euler Method is not very powerful in practical problems, as it
requires very small step size h for reasonable accuracy.

• In Taylor’s method, determination of higher order derivatives are


involved.

• The Runge–Kutta methods give greater accuracy without the


need to calculate higher derivatives.

27
nth order R.K. Method
• This method employs the recurrence formula of the form:

yi+1 = yi + a1 k1 + a2 k2 + L + an kn

where k 1 = h f ( x i, y i)

k2 = h f (xi + p1h, yi + q11 k1)

k3 = h f (xi + p2h, yi + q21 k1 + q22 k2)


……. …….. ………

kn = h f( xi + pn-1 h, yi + q n-1,1 k1 + qn-2, 2 k2 + L q(n-1), (n-1)kn)

28
(II) Runge-Kutta 2nd Order Method
fi h : a1  a2  1 
f  3 eqns,
x h :
2
a2 p1  2 
1

f  4 unknowns
y f i h : a2 q11  2 
2 1

a2  1  a1  0, p1  1 2 , q11  1
2

yi 1  yi  (a1k1  a2 k 2 )h
 yi  k 2 h  yi  f ( xi  p1h, yi  q11 k1h)h
yi 1  yi  f ( xi  12 h, yi  12 f ( xi , yi )) h

1
𝑦 𝑖+1 =𝑦 𝑖 + ( 𝑎1 𝑘1 +𝑎2 𝑘2) h =𝑦 𝑖 + ( 𝑘1 +𝑘2 ) h
2
29
Example 6:
A ball at 1200K is allowed to cool down in air at an ambient temperature of 300K.
Assuming heat is lost only due to radiation, the differential equation for the temperature of
the ball is given by
d
 2.2067  10 12  4  81 10 8 , 0   1200 K
dt

Find the temperature at t  480 seconds using Runge-Kutta 2nd Order method.

Assume a step size of h  240 seconds.

d
 2.2067  10 12  4  81 10 8 
dt

f t ,   2.2067  10 12  4  81 10 8 

1 1 
 i 1   i   k1  k 2 h
2 2 

30
Solution
Step 1: i  0, t0  0,  0   (0)  1200 K

k 2  f t0  h,  0  k1h 
k1  f t0 ,  o 
 f 0  240,1200   4.5579 240 
 f 0,1200 
 f 240,106.09 

 2.2067  10 12 1200 4  81 108   2.2067 10 12 106.09 4  81108 
 4.5579  0.017595

1 1 
1   0   k1  k 2 h
2 2 
1 1 
 1200    4.5579   0.017595240
2 2 
 1200   2.2702 240
 655.16 K

31
Solution Cont.
Step 2: i  1, t1  t 0  h  0  240  240, 1  655.16 K

k1  f t1 ,1  k 2 f t1  h, 1  k1h 


 f 240,655.16  f 240  240,655.16   0.38869240
 2.2067 10 12 655.16 4  81108   f 480,561.87 

 0.38869  2.2067 10 12 561.87 4  81108 


 0.20206

1 1 
 2  1   k1  k 2 h
2 2 
1 1 
 655.16    0.38869    0.20206240
2 2 
 655.16   0.29538240
 584.27 K
32
Comparison of Euler and Runge-Kutta 2nd Order Methods

Table: Comparison of Euler and the Runge-Kutta methods

q(480)
Step size,
h Runge-Kutta 2nd
Euler

480 −987.84 −393.87


240 110.32 584.27
120 546.77 651.35
60 614.97 649.91
30 632.77 648.21

 (480)  647.57 K (exact)

33
(III) Runge-Kutta 4th Order Method
• Mostly commonly used one
• Higher order … more evaluation, but less gain
on accuracy
yn 1  yn  16 (k1  2k 2  2k3  k 4 )h
where
Classical 4th
k1  f ( xn ,yn ) order RK

k 2  f ( xn  12 h,yn  12 k1h)
k3  f ( xn  12 h,yn  12 k 2 h)
k 4  f ( xn  h,yn  k3 h)
34
Example 7:
• Using R.K. Method of 4th order find y(0.1) and y(0.2).

dy
Given that =3x + ½ y, y (0) = 1 taking h = 0.1.
dx

Solution:

k1 = h f (x0, y0) = 0.0500


k2 = h f ( x0 + h2 , y0 + k1
2
) = 0.0663

k3 = h f ( x0 + h2 , y0 + k2
2
) = 0.0667

k4 = h f ( x0 +h, y0 + k3) = 0.0833


y1 = y (0.1) = y0 + 1
6
( k1 + 2k2 + 2k3 + k4) = 1.0674

By similar procedure y(0.2) = 1.1682

35
Example 8:
A ball at 1200K is allowed to cool down in air at an ambient temperature of 300K.
Assuming heat is lost only due to radiation, the differential equation for the temperature of
the ball is given by
d
dt
 
 2.2067  10 12  4  81  10 8 , 0   1200 K

Find the temperature at t  480 seconds using Runge-Kutta 4th order method.

Assume a step size of h  240 seconds.

d
dt

 2.2067  10 12  4  81  10 8 

f t ,   2.2067  10 12  4  81 10 8 
1
 i 1   i  k1  2k 2  2k 3  k 4 h
6
36
Solution
Step 1: i  0, t0  0,  0   (0)  1200

 
k1  f t0 ,  o   f 0,1200   2.2067  10 12 1200 4  81 108  4.5579

 1 1   1 1 
k 2  f  t0  h,  0  k1h   f  0  240 ,1200   4.5579 240 
 2 2   2 2 
 
 f 120,653.05  2.2067  10 12 653.054  81 108  0.38347

 1 1   1 1 
k3  f  t0  h,  0  k 2 h   f  0  240 ,1200   0.38347 240 
 2 2   2 2 
 f 120,1154 .0   2.2067 10 12 1154 .0 4  81108   3.8954

k 4  f t0  h,  0  k3 h   f 0  240 ,1200   3.984 240 



 f 240,265.10   2.2067  10 12 265.10 4  81 108  0.0069750 
37
Solution Cont.
1
1   0  k1  2k2  2k3  k4 h
6
1
 1200   4.5579  2 0.38347   2 3.8954   0.069750240
6
1
 1200   2.1848240
6
 675.65 K

1 is the approximate temperature at

t  t1  t0  h  0  240  240

 240   1  675.65 K

38
Solution Cont.
Step 2: i  1, t1  240,1  675.65 K

 
k1  f t1 , 1   f 240,675.65  2.2067  10 12 675.654  81 108  0.44199

 1 1   1 1 
k 2  f  t1  h, 1  k1h   f  240  240 , 675.65   0.44199 240 
 2 2   2 2 
 
 f 360,622.61  2.2067  10 12 622.614  81 108  0.31372

 1 1   1 1 
k3  f  t1  h, 1  k 2 h   f  240  240 ,675.65   0.31372 240 
 2 2   2 2 
 f 360, 638.00  2.2067 10 12 638.00 4  81108   0.34775

k 4  f t1  h, 1  k3 h   f 240  240 ,675.65   0.34775240 


 f 480,592.19   2.2067 10 12 592.19 4  81108   0.25351

39
Solution Cont.
1
 2  1  k1  2k2  2k3  k4 h
6
1
 675.65   0.44199  2 0.31372  2 0.34775   0.25351240
6
1
 675.65   2.0184 240
6
 594.91K

q2 is the approximate temperature at

t 2  t1  h  240  240  480

 480   2  594.91K

40
Thank you
+974 4495 2222

[email protected]

Location
University of Doha for Science &
Technology
68 Al Tarfa, Duhail North
P.O. Box 24449 Doha, Qatar

You might also like