0% found this document useful (0 votes)
64 views58 pages

Lecture 03 OdE

This document discusses numerical methods for solving ordinary differential equations (ODEs) including the Euler method and Runge-Kutta methods. It provides an overview of the Euler method and how to apply it to solve example ODEs. It also discusses the effects of step size on the accuracy of the Euler method and sources of error. The document notes that the Euler method has large errors and introduces the higher order Runge-Kutta 2nd order method as an improvement over the Euler method.

Uploaded by

cuntnaszer
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)
64 views58 pages

Lecture 03 OdE

This document discusses numerical methods for solving ordinary differential equations (ODEs) including the Euler method and Runge-Kutta methods. It provides an overview of the Euler method and how to apply it to solve example ODEs. It also discusses the effects of step size on the accuracy of the Euler method and sources of error. The document notes that the Euler method has large errors and introduces the higher order Runge-Kutta 2nd order method as an improvement over the Euler method.

Uploaded by

cuntnaszer
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/ 58

Solving ODEs

Euler Method & RK2/4

http://www.mpia.de/homes/mordasini/UKNUM/UeB_ode.pdf

Major: All Engineering Majors

Authors: Autar Kaw, Charlie Barker

http://numericalmethods.eng.usf.edu
Transforming Numerical Methods Education for STEM

02/11/10 http://numericalmethods.eng.usf.edu 1
Simulation example: Formation of Stars
SPH simulation with
gravity and super-
sonic turbulence.

Initial conditions:

Uniform density
1000Msun
1pc diameter
Temperature 10K
Magneto Rotational Instability (MRI) drives
turbulence in accretion disks

12/13/2009
Simulation by Mario Flock using the
Hubert Klahr - Planet Formation - MPIA
Heidelberg Pluto code.
3
Gravoturbulent formation of
Formation Of
Planetesimals planetesimals - Concentration in
From pressure
trapped /
Zonal Flows:
gravitational
Bound heaps of
gravel - here
magnetic
turbulence:

Johansen, Klahr &


Henning 2011.
Vortices: Raettig,
Klahr & Lyra

512 ^2 simulation
64 Mio particles
Entire project used
15 Mio. CPU hours.

12/13/2009 Hubert Klahr - Planet Formation - MPIA 4


Heidelberg
Local collaps 100 x resolution: 0.1 Roche; St: 0.1

Dittrich 2013 PhD thesis


5
MHD plus self-gravity for the dust, including particle feed back on
the gas: Pencil Code: Finite Differenzen / Runge-Kutta 5th order!

gas

dust
Poisson equation solved viaHubert
12/13/2009
FFT inHeidelberg
parallel mode: up to 2563 cells
Klahr - Planet Formation - MPIA
Euler Method




http://numericalmethods.eng.usf.edu


Euler’s Method
y

True value

y1, Predicted
Slope x0,y0 Φ value

Step size, h

Figure 1 Graphical interpretation of the first step of Euler’s method

http://
3 numericalmethods.eng.usf.edu
Euler’s Method
y

True Value

yi+1, Predicted value

Φ
yi
h
Step size
x
xi xi+1

Figure 2. General graphical interpretation of Euler’s method


http://
4 numericalmethods.eng.usf.edu
How to write Ordinary Differential
Equation
How does one write a first order differential equation in the form of

Example

is rewritten as

In this case

http://
5 numericalmethods.eng.usf.edu
Example
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

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

seconds.

http://
6 numericalmethods.eng.usf.edu
Solution
Step 1:

is the approximate temperature at

http://
7 numericalmethods.eng.usf.edu
Solution Cont
Step 2: For

is the approximate temperature at

http://
8 numericalmethods.eng.usf.edu
Solution Cont

The exact solution of the ordinary differential equation is given by the


solution of a non-linear equation as

The solution to this nonlinear equation at t=480 seconds is

http://
9 numericalmethods.eng.usf.edu
Comparison of Exact and
Numerical Solutions
1200,0000

900,0000
θ(K)

Exact Solution
Temperature,

600,0000

h=240
300,0000

0,0000
0 125 250 375 500
Time, t(sec)

Figure 3. Comparing exact and Euler’s method


http://
10 numericalmethods.eng.usf.edu
Effect of step size
Table 1. Temperature at 480 seconds as a function of step size, h

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


480 −987.8 1635.4 252.54
240 1 537.26 82.964
120 110.32 100.80 15.566
60 546.77 32.607 5.0352
30 614.97 14.806 2.2864
(exact)

http://
11 numericalmethods.eng.usf.edu
Comparison with exact results
1200,0000

900,0000 Exact solution


θ(K)

600,0000
h=120
Temperature,

300,0000 h=240

0,0000

-300,0000
h=480
-600,0000

-900,0000

-1200,0000
0 125 250 375 500
Time, t (sec)

Figure 4. Comparison of Euler’s method with exact solution for different step sizes

http://
12 numericalmethods.eng.usf.edu
Effects of step size on Euler’s
Method
750,0000

500,0000

250,0000
θ(K)
Temperature,

0,0000

-250,0000

-500,0000

-750,0000

-1000,0000
0 125 250 375 500
Step size, h (s)

Figure 5. Effect of step size in Euler’s method.


http://
13 numericalmethods.eng.usf.edu
Errors in Euler’s Method
It can be seen that Euler’s method has large errors. This can be illustrated using
Taylor series.

As you can see the first two terms of the Taylor series

are the Euler’s method.


The true error in the approximation is given by

http://
14 numericalmethods.eng.usf.edu
Runge 2nd Order Method

Major: All Engineering Majors

Authors: Autar Kaw, Charlie Barker

http://numericalmethods.eng.usf.edu
Transforming Numerical Methods Education for STEM
Undergraduates

02/11/10 http://numericalmethods.eng.usf.edu 1
Runge-Kutta 2nd Order Method




http://numericalmethods.eng.usf.edu


Runge-Kutta 2nd Order Method
For

Runge Kutta 2nd order method is given by

where

http://
3 numericalmethods.eng.usf.edu
Heun’s Method
Heun’s method
y

Here a2=1/2 is chosen


yi+1, predicted

yi

resulting in

x
xi xi+1

where
Figure 1 Runge-Kutta 2nd order method (Heun’s method)

http://
4 numericalmethods.eng.usf.edu
Midpoint Method
Here is chosen, giving

resulting in

where

http://
5 numericalmethods.eng.usf.edu
Ralston’s Method
Here is chosen, giving

resulting in

where

http://
6 numericalmethods.eng.usf.edu
How to write Ordinary Differential
Equation
How does one write a first order differential equation in the form of

Example

is rewritten as

In this case

http://
7 numericalmethods.eng.usf.edu
Example
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

Find the temperature at seconds using Heun’s method. Assume a step size of

seconds.

http://
8 numericalmethods.eng.usf.edu
Solution
Step 1:

http://
9 numericalmethods.eng.usf.edu
Solution Cont
Step 2:

http://
10 numericalmethods.eng.usf.edu
Solution Cont

The exact solution of the ordinary differential equation is given by the


solution of a non-linear equation as

The solution to this nonlinear equation at t=480 seconds is

http://
11 numericalmethods.eng.usf.edu
Comparison with exact results

Figure 2. Heun’s method results for different step sizes


http://
12 numericalmethods.eng.usf.edu
Effect of step size
Table 1. Temperature at 480 seconds as a function of step size, h

Step size, h θ(480) Et |єt|%

480 −393.87 1041.4 160.82


240 584.27 63.304 9.7756
120 651.35 −3.7762 0.58313
60 649.91 −2.3406 0.36145
30 648.21 −0.63219 0.097625
(exact)

http://
13 numericalmethods.eng.usf.edu
Effects of step size on Heun’s
Method

Figure 3. Effect of step size in Heun’s method

http://
14 numericalmethods.eng.usf.edu
Comparison of Euler and Runge-
Kutta 2nd Order Methods
Table 2. Comparison of Euler and the Runge-Kutta methods

Step θ(480)
size,
Euler Heun Midpoint Ralston
h
480 −987.84 −393.87 1208.4 449.78
240 110.32 584.27 976.87 690.01
120 546.77 651.35 690.20 667.71
60 614.97 649.91 654.85 652.25
(exact)
http://
15 numericalmethods.eng.usf.edu
Comparison of Euler and Runge-
Kutta 2nd Order Methods

Table 2. Comparison of Euler and the Runge-Kutta methods

Step size,
h Euler Heun Midpoint Ralston
480 252.54 160.82 86.612 30.544
240 82.964 9.7756 50.851 6.5537
120 15.566 0.58313 6.5823 3.1092
60 5.0352 0.36145 1.1239 0.72299
30 2.2864 0.097625
0.22353 0.15940

(exact)
http://
16 numericalmethods.eng.usf.edu
Comparison of Euler and Runge-
Kutta 2nd Order Methods
1200,0000

1025,0000 Midpoint
θ(K)
Temperature,

Ralston

850,0000 Heun

Analytical

675,0000
Euler

500,0000
0 125 250 375 500
Time, t (sec)
Figure 4. Comparison of Euler and Runge Kutta 2nd order methods with
exact results. http://
17 numericalmethods.eng.usf.edu
Additional Resources
For all resources on this topic such as digital audiovisual
lectures, primers, textbook chapters, multiple-choice
tests, worksheets in MATLAB, MATHEMATICA, MathCad
and MAPLE, blogs, related physical problems, please
visit

http://numericalmethods.eng.usf.edu/topics/
runge_kutta_2nd_method.html
Runge 4th Order Method


Major: All Engineering Majors

Authors: Autar Kaw, Charlie Barker

http://numericalmethods.eng.usf.edu
Transforming Numerical Methods Education for STEM
Undergraduates

02/11/10 http://numericalmethods.eng.usf.edu 1
Runge-Kutta 4th Order Method




http://numericalmethods.eng.usf.edu


Runge-Kutta 4th Order Method
For

Runge Kutta 4th order method is given by

where

http://
3 numericalmethods.eng.usf.edu
How to write Ordinary Differential
Equation
How does one write a first order differential equation in the form of

Example

is rewritten as

In this case

http://
4 numericalmethods.eng.usf.edu
Example
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

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


Assume a step size of seconds.

http://
5 numericalmethods.eng.usf.edu
Solution
Step 1:

http://
6 numericalmethods.eng.usf.edu
Solution Cont

is the approximate temperature at

http://
7 numericalmethods.eng.usf.edu
Solution Cont
Step 2:

http://
8 numericalmethods.eng.usf.edu
Solution Cont

θ2 is the approximate temperature at

http://
9 numericalmethods.eng.usf.edu
Solution Cont

The exact solution of the ordinary differential equation is given by the


solution of a non-linear equation as

The solution to this nonlinear equation at t=480 seconds is

http://
10 numericalmethods.eng.usf.edu
Comparison with exact results

Figure 1. Comparison of Runge-Kutta 4th order method with exact solution


http://
11 numericalmethods.eng.usf.edu
Effect of step size
Table 1. Temperature at 480 seconds as a function of step size, h

Step size,
θ (480) Et |єt|%
h
480 −90.278 737.85 113.94
240 594.91 52.660 8.1319
120 646.16 1.4122 0.21807
60 647.54 0.033626 0.0051926
30 647.57 0.00086900 0.00013419
(exact)
http://
12 numericalmethods.eng.usf.edu
Effects of step size on Runge-
Kutta 4th Order Method

Figure 2. Effect of step size in Runge-Kutta 4th order method


http://
13 numericalmethods.eng.usf.edu
Comparison of Euler and Runge-
Kutta Methods

Figure 3. Comparison of Runge-Kutta methods of 1st, 2nd, and 4th order.


http://
14 numericalmethods.eng.usf.edu
MHD plus self-gravity for the dust, including particle feed back on
the gas: Pencil Code: Finite Differenzen / Runge-Kutta 5th order!

gas

dust
Poisson equation solved viaHubert
12/13/2009
FFT inHeidelberg
parallel mode: up to 2563 cells
Klahr - Planet Formation - MPIA
THE END
54
55
56
57
58

You might also like