© All Rights Reserved

3 views

© All Rights Reserved

- Errata for Digital Signal Processing A Computer Based Approach 4th edition by Sanjit Mitra
- Class7 - Ode_matlab
- ode45
- Triple Deck Theory
- Adding+Subtracting Polynomials
- MSC III SEM - Copy.docx
- New Behaviour of Extrapolated Runge Kutta Methods
- Interpolation
- BEB20203
- chp_2
- Analysis of Pre Heater Using CFD
- derivatives - Solve the differential equation_ $(y^2-xy)dx+x^2dy=0$ - Mathematics Stack Exchange
- MC0074
- PDE- T6Q9
- MATH Summative 8.1.2
- Assignment-2 Numerical sol of DE 3rd Dec 2018.pdf
- Polynomials for IX
- dg_notes
- Tutorial2_3
- Ch11 Gauss Siedel

You are on page 1of 97

Department of Electrical and Computer Engineering

University of Waterloo

Waterloo, Ontario, Canada

ece.uwaterloo.ca

dwharder@alumni.uwaterloo.ca

4th-order Runge Kutta and the Dormand-Prince Methods

2

Outline

initial value problems:

Weighted averages and integration techniques

Runge-Kutta methods

4th-order Runge Kutta

Adaptive methods

The Dormand-Prince method

The Matlab ode45 function

4th-order Runge Kutta and the Dormand-Prince Methods

3

Outcomes Based Learning Objectives

Understand the 4th-order Runge-Kutta method

Comprehend why adaptive methods are required to reduce the

error but also reduce the effort

Understand the algorithm for the Dormand-Prince method

4th-order Runge Kutta and the Dormand-Prince Methods

4

Weighted Averages

The average of five numbers x1, x2, x3, x4, and x5 is:

x1 x2 x3 x4 x5 1

x 5 x1 15 x2 15 x3 15 x4 15 x5

5

projects had twice the weight of the other projects

We can calculate the following weighted average:

1

7 x1 17 x2 17 x3 72 x4 72 x5

4th-order Runge Kutta and the Dormand-Prince Methods

5

Weighted Averages

such that

a1 a2 a3 a4 a5 1

a1 x1 a2 x2 a3 x3 a4 x4 a5 x5

1

3 13 13 13 13 1

1

3 x1 13 x2 13 x3 13 x4 13 x5

3 13 1, 16

15 15 1

1

4th-order Runge Kutta and the Dormand-Prince Methods

6

Integration

approximating integrals

b

We wish to approximate f x dx

a

4th-order Runge Kutta and the Dormand-Prince Methods

7

Integration

Approximate the integral by calculating the area of the square

f x dx f x x

a

1 2 x1

a= =b

4th-order Runge Kutta and the Dormand-Prince Methods

8

Integration

f x dx f x x

a

2 3 x1

a= =b

4th-order Runge Kutta and the Dormand-Prince Methods

9

Integration

This weighted average calculates the area of the trapezoid

1

b

1

f x dx f x1 f x2 x2 x1

a 2 2

a= =b

4th-order Runge Kutta and the Dormand-Prince Methods

10

Integration

This calculates the area of two trapezoids

1

b

1 1

f x dx f x1 f x2 f x3 x3 x1

a 4 2 4

The composite

trapezoidal rule

a= =b

4th-order Runge Kutta and the Dormand-Prince Methods

11

Integration

point

This calculates the area under the interpolating quadratic

function

1

b

2 1

f x dx f x1 f x2 f x3 x3 x1

a 6 3 6

Simpsons rule

a= =b

4th-order Runge Kutta and the Dormand-Prince Methods

12

Integration

weights

This calculates the area under the interpolating quadratic

function

b

f x dx f x1 f x2 f x3 f x4 x4 x1

1 3 3 1

a

8 8 8 8

a= =b

4th-order Runge Kutta and the Dormand-Prince Methods

13

Initial-value Problems

better approximations of an initial-value problem

Eulers method

Heuns method

The 4th-order Runge Kutta method

The Dormand-Prince method

4th-order Runge Kutta and the Dormand-Prince Methods

14

Initial-value Problems

and an initial condition

y1 t f t , y t

y t0 y0

we would like to approximate a solution

4th-order Runge Kutta and the Dormand-Prince Methods

15

Initial-value Problems

y t y t 2 t t t 1

1

y 0 1

4th-order Runge Kutta and the Dormand-Prince Methods

16

Initial-value Problems

y t y t 2 t t t 1

1

y 0 1

4th-order Runge Kutta and the Dormand-Prince Methods

17

Eulers Method

sample: K1 f tk , yk

yk 1 yk hK1

4th-order Runge Kutta and the Dormand-Prince Methods

18

Eulers Method

y t y t 2 t t t 1

1

y 0 1

4th-order Runge Kutta and the Dormand-Prince Methods

19

Eulers Method

y t y t 2 t t t 1

1

y 0 1 y 0.5 y1 y0 0.5 1

1 0.5 0.5

4th-order Runge Kutta and the Dormand-Prince Methods

20

Eulers Method

y t y t 2 t t t 1

1

y 0 1

4th-order Runge Kutta and the Dormand-Prince Methods

21

Heuns Method

samples: K1 f tk , yk

K 2 f tk h, yk hK1

the next point:

K1 K 2

yk 1 yk h

2

4th-order Runge Kutta and the Dormand-Prince Methods

22

Heuns Method

y t y t 2 t t t 1

1

y 0 1

K1 1

K 2 f 0.5, 0.5

0.5 1.5 0.5 0.5 1

0.125

4th-order Runge Kutta and the Dormand-Prince Methods

23

Heuns Method

y t y t 2 t t t 1

1

y 0 1

K1 K1 1 0.125

2 2

0.5625

y 0.5

y1 1 0.5 0.5625

0.71875

4th-order Runge Kutta and the Dormand-Prince Methods

24

Heuns Method

y t y t 2 t t t 1

1

y 0 1

K1 K1 1 0.125

2 2

0.5625

4th-order Runge Kutta and the Dormand-Prince Methods

25

Mid-point Method

Use Eulers method to find in the slope in the middle with h/2:

K1 f tk , yk

1 1

K 2 f tk h , yk h K1

2 2

This second slope is then used to approximate the next

point:

yk 1 yk hK2

4th-order Runge Kutta and the Dormand-Prince Methods

26

Mid-point Method

y t y t 2 t t t 1

1

y 0 1

K1 f 0,1

K 2 f 0.25,1 0.25 1

f 0.25, 0.75

0.421875

4th-order Runge Kutta and the Dormand-Prince Methods

27

Mid-point Method

y t y t 2 t t t 1

1

0.7890625

4th-order Runge Kutta and the Dormand-Prince Methods

28

Mid-point Method

y t y t 2 t t t 1

1

y 0 1

4th-order Runge Kutta and the Dormand-Prince Methods

29

4th-order Runge-Kutta Method

starting at the midpoint tk + h/2:

K1 f tk , yk

K 2 f tk 12 h, yk 12 h K1

4th-order Runge Kutta and the Dormand-Prince Methods

30

4th-order Runge-Kutta Method

K1 f tk , yk

K 2 f tk 12 h, yk 12 h K1

K3 f tk 12 h, yk 12 h K 2

4th-order Runge Kutta and the Dormand-Prince Methods

31

4th-order Runge-Kutta Method

K1 f tk , yk

K 2 f tk 12 h, yk 12 h K1

K3 f tk 12 h, yk 12 h K 2

K 4 f tk h, yk h K3

4th-order Runge Kutta and the Dormand-Prince Methods

32

4th-order Runge-Kutta Method

K1 f tk , yk

K 2 f tk 12 h, yk 12 h K1

K3 f tk 12 h, yk 12 h K 2

K 4 f tk h, yk h K3

and approximate yk 1 yk h 16 K1 13 K2 13 K3 16 K4

K1 f tk , yk

K 2 f tk h, yk hK1 yk 1 yk h 12 K1 12 K2

4th-order Runge Kutta and the Dormand-Prince Methods

33

4th-order Runge-Kutta Method

y t y t 2 t t t 1

1

y 0 1

4th-order Runge Kutta and the Dormand-Prince Methods

34

4th-order Runge-Kutta Method

y t y t 2 t t t 1

1

y 0 1

4th-order Runge Kutta and the Dormand-Prince Methods

35

4th-order Runge-Kutta Method

y t y t 2 t t t 1

1

y 0 1

4th-order Runge Kutta and the Dormand-Prince Methods

36

4th-order Runge-Kutta Method

y t y t 2 t t t 1

1

y 0 1

4th-order Runge Kutta and the Dormand-Prince Methods

37

4th-order Runge-Kutta Method

y t y t 2 t t t 1

1

y 0 1

4th-order Runge Kutta and the Dormand-Prince Methods

38

4th-order Runge-Kutta Method

y t y t 2 t t t 1

1

y 0 1

4th-order Runge Kutta and the Dormand-Prince Methods

39

4th-order Runge-Kutta Method

y t y t 2 t t t 1

1

y 0 1

4th-order Runge Kutta and the Dormand-Prince Methods

40

4th-order Runge-Kutta Method

y t y t 2 t t t 1

1

y 0 1

4th-order Runge Kutta and the Dormand-Prince Methods

41

4th-order Runge-Kutta Method

y t y t 2 t t t 1

1

y 0 1

y (0.5) 0.7963901345956429

Euler: 0.5

Heun: 0.71875

Mid-point: 0.7890625

4th-order R-K: 0.79620615641666

4th-order Runge Kutta and the Dormand-Prince Methods

42

4th-order Runge-Kutta Method

y t y t 2 t t t 1

1

y 0 1

4th-order Runge Kutta and the Dormand-Prince Methods

43

4th-order Runge-Kutta Method

y t y t 2 t t t 1

1

y 0 1

4th-order Runge Kutta and the Dormand-Prince Methods

44

4th-order Runge-Kutta Method

y t y t 2 t t t 1

1

y 0 1

4th-order Runge Kutta and the Dormand-Prince Methods

45

4th-order Runge-Kutta Method

As an example,

>> format long

>> [t2a, y2a] = rk4( @f2a, [0, 1], 0, 2 )

t2a =

0 1

y2a =

0 0.265706380208333

>> [t2a, y2a] = rk4( @f2a, [0, 1], 0, 3 )

t2a =

0 0.500000000000000 1.000000000000000

y2a =

0 0.227653163407674 0.251787629335613

>> [t2a, y2a] = rk4( @f2a, [0, 1], 0, 4 )

t2a =

0 0.333333333333333 0.666666666666667 1.000000000000000

y2a =

0 0.190364751129471 0.243328110416578 0.250335465183716

4th-order Runge Kutta and the Dormand-Prince Methods

46

4th-order Runge-Kutta Method

for k = 1:(n 1)

K1 f tk , yk % Find the four slopes K1, K2, K3, K4

K 2 f tk 12 h, yk 12 h K1 % Given y(k), find y(k + 1) by adding

K3 f tk 12 h, yk 12 h K 2 % h times the weighted average

end

K 4 f tk h, yk h K3

yk 1 yk h 16 K1 13 K2 13 K3 16 K4

4th-order Runge Kutta and the Dormand-Prince Methods

47

Runge-Kutta Methods

first slope K1 f tk , yk

K2 f tk c2h, yk c2hK1

4th-order Runge Kutta and the Dormand-Prince Methods

48

Runge-Kutta Methods

K3 f tk c3h, yk c3h a3,1K1 a3,2 K 2

where a3,1 a3,2 1 defines a weighted average

and K3 to approximate the next point:

yk 1 yk h b1K1 b2 K2 b3 K3

where b1 b2 b3 1

4th-order Runge Kutta and the Dormand-Prince Methods

49

Runge-Kutta Methods

A = [0 0 0 0

K1 f tk , yk 1 0 0 0

K 2 f tk 12 h, yk 12 h K1 0 1 0 0

0 0 1 0];

K3 f tk 12 h, yk 12 h K 2 c = [0 1/2 1/2 1]';

b = [1/6 1/3 1/3 1/6];

K 4 f tk h, yk h K3

yk 1 yk h 16 K1 13 K2 13 K3 16 K4 0

1

1

c A 2

1

0 1

b 2

1 0 0 1

1 1 1 1

6 3 3 6

4th-order Runge Kutta and the Dormand-Prince Methods

50

Runge-Kutta Methods

A = [0 0 0 0 t0 = t_rng(1);

1 0 0 0 tf = t_rng(2);

0 1 0 0 h = (tf - t0)/(n - 1);

0 0 1 0]'; t_out = linspace( t0, tf, n );

c = [0 1/2 1/2 1]'; y_out = zeros( 1, n );

b = [1/6 1/3 1/3 1/6]'; y_out(1) = y0;

k_n = 4;

for k = 1:(n - 1)

K = zeros( 1, k_n );

K1 f tk , yk for m = 1:k_n

K 2 f tk 12 h, yk 12 h K1 K(m) = f( t_out(k) + h*c(m), ...

y_out(k) + h*c(m)*K*A(m,:) );

K3 f tk 12 h, yk 12 h K 2 end

end

yk 1 yk h 16 K1 13 K2 13 K3 16 K4

4th-order Runge Kutta and the Dormand-Prince Methods

51

Butcher Tableau

0

For Heuns method: 1 1

1 1

2 2

0

1

2 1

For the 4th-order Runge-Kutta method: 1

2 0 1

1 0 0 1

1 1 1 1

6 3 3 6

4th-order Runge Kutta and the Dormand-Prince Methods

52

Butcher Tableau

0 0

1 1 1

2 1 2 2

1 1 1

2 0 1 2 0 2

1 0 0 1 1 0 0 1

1 1 1 1 1 1 1 1

6 3 3 6 6 3 3 6

4th-order Runge Kutta and the Dormand-Prince Methods

53

Comparison

The initial-value problem

y (1) t y t 1 t 1

2 2

y 0 0

t 3 3t 2 3t

y t 3

t 3t 2 3t 3

function [dy] = f2a(t, y)

dy = (y - 1).^2 .* (t - 1).^2;

end

y = (t.^3 - 3*t.^2 + 3*t)./(t.^3 - 3*t.^2 + 3*t + 3);

end

4th-order Runge Kutta and the Dormand-Prince Methods

54

Comparison

the same:

Euler: n = 17

Heun: n=9

4th-order Runge Kutta n=5

n = 4;

[t2e, y2e] = euler( @f2a, [0, 1], 0, 4*n+1 );

[t2h, y2h] = heun( @f2a, [0, 1], 0, 2*n+1 );

[t2r, y2r] = rk4( @f2a, [0, 1], 0, n+1 );

t2s = linspace( 0, 1, 101 );

hold on

plot( t2h, y2h, 'd' )

plot( t2r, y2r, 'mo' )

plot( t2s, y2a( t2s ), 'k' )

4th-order Runge Kutta and the Dormand-Prince Methods

55

Comparison

scale:

Euler 4th-order Runge Kutta o

Heun ode45 ___

4th-order Runge Kutta and the Dormand-Prince Methods

56

Comparison

errors for a greater number of points:

n = 20;

[t2e, y2e] = euler( @f2a, [0, 1], 0, 4*n+1 );

[t2h, y2h] = heun( @f2a, [0, 1], 0, 2*n+1 );

[t2r, y2r] = rk4( @f2a, [0, 1], 0, n+1 );

t2s = linspace( 0, 1, 101 );

hold on

plot( t2h, log10(abs(y2h - y2a( t2h ))), '.b' )

plot( t2r, log10(abs(y2r - y2a( t2r ))), '.m' )

4th-order Runge Kutta and the Dormand-Prince Methods

57

Comparison

The error for Eulers method is around 102

Heuns method has an error around 105

The 4th-order Runge-Kutta method has an error around 107

Euler

Log of Error

Heun

4th-order Runge Kutta and the Dormand-Prince Methods

58

4th-order Runge Kutta

y (1) t t y t y t t cos y t

y 0 1

n = 4;

[t2e, y2e] = euler( @f2b, [0, 1], 1, 4*n+1 );

[t2h, y2h] = heun( @f2b, [0, 1], 1, 2*n+1 );

[t2r, y2r] = rk4( @f2b, [0, 1], 1, n+1 );

[t2o, y2o] = ode45( @f2b, [0, 1], 1 );

hold on

plot( t2h, y2h, 'bd' )

plot( t2r, y2r, 'mo' )

plot( t2o, y2o, 'k' )

4th-order Runge Kutta and the Dormand-Prince Methods

59

Comparison

scale:

Euler 4th-order Runge Kutta o

Heun ode45 ___

4th-order Runge Kutta and the Dormand-Prince Methods

60

Comparison

errors:

n = 20;

[t2e, y2e] = euler( @f2b, [0, 1], 1, 4*n+1 );

[t2h, y2h] = heun( @f2b, [0, 1], 1, 2*n+1 );

[t2r, y2r] = rk4( @f2b, [0, 1], 1, n+1 );

options = odeset( 'RelTol', 1e-13, 'AbsTol', 1e-13 );

[t2o, y2o] = ode45( @f2b, [0, 1], 1, options );

hold on

plot( t2h, log10(abs(y2h - interp1( t2o, y2o, t2h ))), '.b' )

plot( t2r, log10(abs(y2r - interp1( t2o, y2o, t2r ))), '.m' )

function with very high relative and absolute tolerances

4th-order Runge Kutta and the Dormand-Prince Methods

61

Comparison

The error for Eulers method is around 102

Heuns method has an error around 104

The 4th-order Runge-Kutta method has an error around 106

Euler

Log of Error

Heun

4th-order Runge Kutta and the Dormand-Prince Methods

62

The Dormand-Prince Method

methods, we may now go on to the current algorithm

used in Matlab today

The routine ode45 uses the Dormand-Prince method

4th-order Runge Kutta and the Dormand-Prince Methods

63

The Dormand-Prince Method

y t y t 2 t t t 1

1

y 0 1

The best Maple can do is give an answer in terms of an integral:

> dsolve( {D(y)(t) = y(t)*(2 - t)*t + t - 1, y(0) = 1} );

t 13 2 3 13 t 2 3t

y t e 1 d 1 e

0

No antiderivative

4th-order Runge Kutta and the Dormand-Prince Methods

64

The Dormand-Prince Method

y t y t 2 t t t 1

1

dy = y*(2 - t)*t + t - 1; y 0 1

end

And then call:

>> [t3a, y3a] = ode45( @f3a, [0, 5], 1 );

>> plot( t3a, y3a );

4th-order Runge Kutta and the Dormand-Prince Methods

65

The Dormand-Prince Method

>> plot( t3a, y3a, '.' );

Dormand-Prince is adaptiveit attempts to optimize the interval

size

4th-order Runge Kutta and the Dormand-Prince Methods

66

The Dormand-Prince Method

>> length( t3a );

ans = 69

4th-order Runge Kutta and the Dormand-Prince Methods

67

Adaptive Techniques

of the interval?

better than the other:

For example, Eulers method and Heuns method

Given a point (tk, yk), use both methods to approximate the next

point:

1 k k

K f t ,y

K2 f tk h, yk hK1

ytmp yk hK1 Eulers method

K1 K 2

ztmp yk h

2

Heuns method

4th-order Runge Kutta and the Dormand-Prince Methods

68

Adaptive Techniques

y t y t

1

y 0 1

start with h = 0.1 and we want to ensure that the error is

not larger than eabs = 0.001

K1 f 0,1 1

K 2 f 0.1,1 0.1K1 0.9

ytmp 1 0.1 1 0.9 Eulers method

ztmp 1 0.1

1 0.9

0.905

2

Heuns method

4th-order Runge Kutta and the Dormand-Prince Methods

69

Adaptive Techniques

One is okay, the other is better

ytmp 0.9

ztmp 0.905

ytmp e 0.1 0.9 0.9048374180 0.0048374180

ytmp ztmp 0.9 0.905 0.005

4th-order Runge Kutta and the Dormand-Prince Methods

70

Adaptive Techniques

approximation of the error of ytmp

willing to tolerate

In this case, the error should be less than eabs = 0.001

Question: how much smaller?

4th-order Runge Kutta and the Dormand-Prince Methods

71

Adaptive Techniques

that is

ytmp ztmp Ch 2 for some value of C

C sh e abs

2

4th-order Runge Kutta and the Dormand-Prince Methods

72

Adaptive Techniques

The contribution of the maximum error at the kth step should be

proportional to the width of the interval relative to the whole

interval

sh

C sh e abs

2

t f t0

1 sh e abs sh

C sh e abs

2

2 t f t0 2 t f t0

4th-order Runge Kutta and the Dormand-Prince Methods

73

Adaptive Techniques

e abs sh

C sh

2

ytmp ztmp Ch

2 t f t0

2

e abs sh

Cs h

2 2

2 t f t0

e abs h

s Ch 2

2 t f t0

We can now substitute the first equation for Ch2:

e abs h

s ytmp ztmp

2 t f t0

4th-order Runge Kutta and the Dormand-Prince Methods

74

Adaptive Techniques

e abs h

s ytmp ztmp

2 t f t0

e abs h

s

2 t f t0 ytmp ztmp

4th-order Runge Kutta and the Dormand-Prince Methods

75

Adaptive Techniques

h 0.1

e abs 0.001

ytmp ztmp 0.005

[t0 , t f ] [0, 0.1]

e abs h 0.001 0.1

s 0.1

2 t f t0 ytmp ztmp 2 0.1 0.005

4th-order Runge Kutta and the Dormand-Prince Methods

76

Adaptive Techniques

K1 f 0,1 1

K 2 f 0.01,1 0.01 K1 0.99

ytmp 1 0.01 1 0.99 Eulers method

1 0.99

ztmp 1 0.01 0.99005

2

Heuns method

The absolute error using Eulers method is 0.0000498337 which

e abs h

0.00005

2 t f t0

is of the same order of

4th-order Runge Kutta and the Dormand-Prince Methods

77

Adaptive Techniques

>> t_out =

0 0.0100 0.0200 0.0301 0.0403 0.0506 0.0610 0.0715 0.0822 0.0929 0.1

>> y_out =

1 0.9900 0.9801 0.9702 0.9603 0.9504 0.9405 0.9306 0.9207 0.9108 0.9044

>> y_out(end)

0.904837418035960

>> exp( -0.1 )

0.904837418035960

>> abs( y_out(end) - exp( -0.1 ) )

4.599948547183708e-004 e abs

0.0005

2

4th-order Runge Kutta and the Dormand-Prince Methods

78

Adaptive Techniques

h = s*h;

as s could be either very big or very small

change too much in the short run:

If s 2, double the value of h

If 1 s < 2, leave h unchanged, and

If s < 1, halve h and try again

4th-order Runge Kutta and the Dormand-Prince Methods

79

The Dormand-Prince Method

K1, K2, K3, K4, K5, K6, and K7

These slopes are then used in two different linear

combinations to find two approximations of the next

point:

One is O(h4) while the other is O(h5)

The coefficients of the 5th-order approximate were chosen to

minimize its error

We now use these two approximations to find s:

he abs

s4

2 t f t0 ytmp ztmp

4th-order Runge Kutta and the Dormand-Prince Methods

80

The Dormand-Prince Method

method is:

0

1

5 1

3 1 3

10 4 4

4

5

11

9 143 40

9

8

9

4843

1458 3170

243

8056

729 162

53

1 9017

3168 355

33

46732

5247

49

176 18656

5103

1 35

384 0 500

113

125

192 2187

6784

11

84

5179

57600 0 7571

16695

393

640 339200

92097 187

2100

1

40

O(h4) approximation

35

384 0 500

1113

125

192 2187

6784

11

84 0 O(h5) approximation

4th-order Runge Kutta and the Dormand-Prince Methods

81

The Dormand-Prince Method

0

1

5 1

3 1 3

10 4 4

4

5

11

9 143 40

9

8

9

4843

1458 3170

243

8056

729 162

53

1 9017

3168 355

33

46732

5247

49

176 18656

5103

1 35

384 0 500

113

125

192 2187

6784

11

84

5179

57600 0 7571

16695

393

640 339200

92097 187

2100

1

40

35

384 0 500

1113

125

192 2187

6784

11

84 0

4th-order Runge Kutta and the Dormand-Prince Methods

82

The Dormand-Prince Method

In the literature, for example, the fourth row would be multiplied

0

by 4/5: 1

5 1

3 1 3

10 4 4

4

5

11

9 143 40

9

8

9

4843

1458 3170

243

8056

729 162

53

1 9017

3168 355

33

46732

5247

49

176 18656

5103

1 35

384 0 500

113

125

192 2187

6784

11

84

5179

57600 0 7571

16695

393

640 339200

92097 187

2100

1

40

35

384 0 500

1113

125

192 2187

6784

11

84 0

4th-order Runge Kutta and the Dormand-Prince Methods

83

The Dormand-Prince Method

A = [ 0 0 0 0 0 0 0;

1 0 0 0 0 0 0;

1/4 3/4 0 0 0 0 0;

11/9 -14/3 40/9 0 0 0 0;

4843/1458 -3170/243 8056/729 -53/162 0 0 0;

9017/3168 -355/33 46732/5247 49/176 -5103/18656 0 0;

35/384 0 500/1113 125/192 -2187/6784 11/84 0]';

bz = [ 35/384 0 500/1113 125/192 -2187/6784 11/84 0]';

4th-order Runge Kutta and the Dormand-Prince Methods

84

The Dormand-Prince Method

A = [...]';

c = [...]';

by = [...]';

bz = [...]';

// ...

n_K = 7;

K = zeros( 1, n_K );

for m = 1:n_K

kvec(m) = f( t_out(k) + h*c(m), ...

y_out(k) + h*c(m)*K*A(m,:) );

end

y = y_out(k) + h*K*by;

z = y_out(k) + h*K*bz;

4th-order Runge Kutta and the Dormand-Prince Methods

85

The Dormand-Prince Method

What value of h?

Previously, we specified the interval and the number of points

ode45 actually determines a good initial value of h

The value of h could increase or decrease depending on the

problem

We will have to have a different counter tracking where we are in

the array

4th-order Runge Kutta and the Dormand-Prince Methods

86

The Dormand-Prince Method

>> t_out = 1

t_out =

1

t_out =

1.0000 1.1000

t_out =

1.0000 1.1000 1.2000

ans =

1 3

4th-order Runge Kutta and the Dormand-Prince Methods

87

The Dormand-Prince Method

% Initialize t_out and y_out

% Initialize our location to k = 1

%

% while t_out(k) < tf

% Use Dormand Prince to find two approximations

% y and z to approximate y(t) at t = t_out(k) + h

% for the current value of h

%

% Calculate the scaling factor 's'

%

% if s >= 2,

% We use y to approximate y_out(k + 1)

% t_out(k + 1) is the previous t-value plus h

% Increment k and double the value of h for the

% next iteration.

4th-order Runge Kutta and the Dormand-Prince Methods

88

The Dormand-Prince Method

% else if s >= 1,

% We use y to approximate y_out(k + 1)

% t_out(k + 1) is the previous t-value plus h

% In this case, h is neither too large or too

% small, so only increment k

% else s < 1

% Divide h by two and try again with the smaller

% value of h (just go through the loop again

% without updating t_out, y_out, or k)

% end

%

% We must make one final check before we end the loop:

% if t_out(k) + h > tf, we must reduce the

% size of h so that t_out(k) + h == tf

% end

4th-order Runge Kutta and the Dormand-Prince Methods

89

Runge-Kutta Methods

As an example,

>> format long

>> [t2a_out, y2a_out] = dp45( @f2a, [0, 1], 0, 0.1, 0.001 )

t2a_out =

0 0.100000000000000 0.300000000000000 0.700000000000000 1.000000000000000

y2a_out =

0 0.082849167706690 0.179652764494993 0.244888142029126 0.249985161828570

t2a_out =

0 0.100000000000000 0.300000000000000 0.500000000000000 0.900000000000000 1.000000000000000

y2a_out =

0 0.082849167706690 0.179652764494993 0.225803586411837 0.249807784433138 0.249995333556517

y (1) t y t 1 t 1

2 2

y 0 0

4th-order Runge Kutta and the Dormand-Prince Methods

90

Runge-Kutta Methods

four steps are

t1 = 0.0 1.000000000000000

h = 0.1

0.922368160000000

0.888484042496882

Approximating t2 = 0.1 K T 0.733102686848602

0.707007263868476

y = 0.082849167706690

z = 0.082849238339751 0.678484594287190

0.681344070887320

s = 2.900617713421327

4th-order Runge Kutta and the Dormand-Prince Methods

91

Runge-Kutta Methods

four steps are

t2 = 0.1 0.681344175832812

h = 0.2

0.585701655486480

0.547129816073037

Approximating t3 = 0.3 K 0.379211319350047

T

0.350996539397804

y = 0.179652764494993

z = 0.179654500779400 0.323819720073735

0.329753701664832

s = 1.549154681332583

4th-order Runge Kutta and the Dormand-Prince Methods

92

Runge-Kutta Methods

four steps are

t3 = 0.3 0.329755097532346

h = 0.2

0.283794477529483

0.263870533555760

Approximating t4 = 0.5 K 0.177464214824161

T

0.164101192287057

y = 0.225803586411837

z = 0.225804013589520 0.149107161192848

0.149844856343524

s = 2.199621019421089

4th-order Runge Kutta and the Dormand-Prince Methods

93

Runge-Kutta Methods

four steps are

t4 = 0.5 0.149845021703193

h = 0.4

0.102481744933332

0.083510323663559

Approximating t5 = 0.9 K 0.018218173715833

T

0.011628711293105

y = 0.249807784433138

z = 0.249809573055606 0.005569794874352

0.005627856766790

s = 1.828638370749953

Note: but 0.9 + 0.4 > 1, so use h = 1 0.9 = 0.1

4th-order Runge Kutta and the Dormand-Prince Methods

94

Runge-Kutta Methods

four steps are

t5 = 0.9 0.005627883602971

h = 0.1

0.003600764756401

0.002756757094183

Approximating t6 = 1.0: K 0.000225003623309

T

0.000069445279659

y = 0.249995333556517

z = 0.249995333705456 0

0

s = 13.535998941577226

Remember, we artificially reduced h

4th-order Runge Kutta and the Dormand-Prince Methods

95

The Dormand-Prince Method

6 and in NE 217

Dormand-Prince is the algorithm used in the Matlab ODE solver

>> help ode45

ODE45 Solve non-stiff differential equations, medium order method.

[TOUT,YOUT] = ODE45(ODEFUN,TSPAN,Y0) with TSPAN = [T0 TFINAL]

integrates the system of differential equations y' = f(t,y) from

time T0 to TFINAL with initial conditions Y0.

ODEFUN(T,Y) must return a column vector corresponding to f(t,y).

returned in the column vector TOUT.

4th-order Runge Kutta and the Dormand-Prince Methods

96

Summary

better techniques:

Weighted averages and integration techniques

4th-order Runge Kutta

Adaptive methods

The Dormand-Prince method

4th-order Runge Kutta and the Dormand-Prince Methods

97

References

[1] Glyn James, Modern Engineering Mathematics, 4th Ed., Prentice Hall,

2007.

Prentice Hall, 2011.

formulae," J. Comp. Appl. Math., Vol. 6, 1980, pp. 19-26.

- Errata for Digital Signal Processing A Computer Based Approach 4th edition by Sanjit MitraUploaded byderpington
- Class7 - Ode_matlabUploaded byMohd Fauzi Zanil
- ode45Uploaded byBagus Pamungkas
- Triple Deck TheoryUploaded bykrishnamurthyVish
- Adding+Subtracting PolynomialsUploaded byGladys Gahona
- MSC III SEM - Copy.docxUploaded byparveshnain19
- New Behaviour of Extrapolated Runge Kutta MethodsUploaded byAzri Zaini
- InterpolationUploaded byRavi Parkhe
- BEB20203Uploaded byHairil Hanif
- chp_2Uploaded byMichael Vladislav
- Analysis of Pre Heater Using CFDUploaded byParthibann Radhabose
- derivatives - Solve the differential equation_ $(y^2-xy)dx+x^2dy=0$ - Mathematics Stack ExchangeUploaded byAbhishek Patra
- MC0074Uploaded bysazizulla
- PDE- T6Q9Uploaded byBumi Bums
- MATH Summative 8.1.2Uploaded byaisa cuerda
- Assignment-2 Numerical sol of DE 3rd Dec 2018.pdfUploaded byPrashant Kulkarni
- Polynomials for IXUploaded bySudersanaViswanathan
- dg_notesUploaded byNishant Panda
- Tutorial2_3Uploaded byjawaidalig
- Ch11 Gauss SiedelUploaded byZaher Zaher
- Gauss IntegrationUploaded byShadi
- Newton Rapson MethodUploaded byVikas Varshney
- 3G Optimization Ph3 Report_NOE_Hotspot(CL Week9)Uploaded byst20795
- Day27 PDE Heat Equation ImplicitUploaded byCristian Paduraru
- Ch4 FiguresUploaded bytarek moahmoud khalifa
- Freesat Huffman Table (Compression Type 2)Uploaded bySergio Caceres
- Fardapaper a Grasshopper Optimization Algorithm to Solve Optimal Distribution System Reconfiguration and Distributed Generation Placement ProblemUploaded byFelix Palangan
- 140617000042 m2.pdfUploaded byAnonymous AGCjGIp
- Interpolasi Lagrange Contoh KodeUploaded bySion Halim
- QUANTATIVE TECHNIQUE.pptxUploaded byRajib Ghoshal

- Kattan_CDUploaded bySebastiao Silva
- questionsUploaded byfake7083
- Vocub list.docxUploaded byfake7083
- Vocub.docxUploaded byfake7083
- matlab code interpollationUploaded byfake7083
- Cfd NotesUploaded byfake7083
- MDSRC AbstractUploaded byfake7083
- Kapitza ConductanceUploaded byfake7083
- Velocity and Temperature profiles in ConvectionUploaded byfake7083
- Fluid Mechanics Assignment No 4Uploaded byfake7083
- fluid mechanics assignment 5Uploaded byfake7083
- Solution of Assignment No 2Uploaded byfake7083
- AE 753 Advance Heat TransferUploaded byfake7083
- Matlab Code 1D FEMUploaded byfake7083
- 1D FEMUploaded byfake7083
- Formula Sheet for Maths AmendUploaded byfake7083
- Numerical Methods Formula Sheet - CopyUploaded byfake7083
- Numerical Methods Formula SheetUploaded byfake7083
- README14.pdfUploaded byfake7083
- Newton Raphson MethodUploaded byfake7083
- Equation of Motion of AirfoilUploaded byfake7083
- Air Amplifiers SystemsUploaded byfake7083
- 59070_8668_CH06Uploaded byravimech223669
- 2. Ijmperd - Analysis of Foreign Object Impact on AircraftUploaded byTJPRC Publications
- 12ULBevregs.pdfUploaded byfake7083
- the Expanded Role of Air Power in the Defence and Security of SingaporeUploaded byfake7083

- Gödel, Escher, Bach_ An Eternal Golden Braid (20th Anniversary Edition) by Douglas R. Hofstadter {Charm-Quark}.pdfUploaded byClaudiu Cantor
- Effect of Alccofine and Foundry Slag on Compressive Strength of High Strength ConcreteUploaded byInnovative Research Publications
- Fluoresscent DNA NanotagsUploaded byreolox
- Aircraft DesignUploaded bySonia Yadav
- Circular CurveUploaded byqaiserkhan001
- Chapter 1Uploaded byRita Lau
- 1002.2269 CEO EntropyUploaded byYùht Hna
- Interaction Diagram for Concrete ColumnsUploaded bygeogohigh
- musical notes lab 4Uploaded byapi-263251621
- Katalog G Serie 2007Uploaded byVinicius Bacellar
- Algorithms_ Dynamic Programming - Matrix Chain Multiplication With C Program Source Code - The Learning PointUploaded byGautam Jha
- Sodium MethylParaben MSDSUploaded byterryzhai
- integrationUploaded byKajal Joshi
- Electrical Monitoring System & Services_backupUploaded by3319826
- The Ising ModelUploaded byvertugo
- Arsenio MontaleUploaded by1inutil
- Rotordynamics.pdfUploaded byhihou
- Eco Cycle DesignUploaded byKiran Sunku
- Moon (Tides and the Moon)Uploaded byWael Zak
- 10 Mathematics Impq Sa 2 4 Some Applications of Trigonometry 2Uploaded byJesse Sanders
- Rheology of Oil Well Cement SlurriesUploaded byHernan Cabrera Pantoja
- CEDD Cement SoilUploaded byDelon Yau
- Rosicrucian Digest, May 1951Uploaded bysauron385
- Atlas Munsell ColorUploaded byBintarjo Agus Priyadi
- Cheguide.com 2015 12 Heat-loss-from-Insulated-pipeUploaded byRamu Nallathambi
- 25045-C5420-16-SSC-S-110Uploaded byHema Chandra Indla
- Prout PolicyUploaded byAnanta
- ode_msuUploaded byPuteri Haslinda
- 9702_s15_qp_21Uploaded bywnwd97
- Machine Design TerminologiesUploaded byJennie Vicenta