Top Banner
RungeKu(a Methods
33

Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Mar 10, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Runge-­‐Ku(a  Methods  

Page 2: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

over

Review  of  Heun’s  Method  (Deriva:on  from  Integra:on)  

The idea is to construct an algorithm to solve the IVP ODE

(8.1)

To obtain the solution point we can use the fundamental theorem of calculus and integrate over

to get

(8.2)

Page 3: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

A numerical integration method can be used to approxi- mate the definite integral in equation (8.3). If the trape- zoidal rule (Lecture 5) is used with the step size

Review  of  Heun’s  Method  (Deriva:on  from  Integra:on)  

When equation (8.2) is solved from

(8.3)

the result is

the result is

(8.4)

Page 4: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

we use Euler’s forward method

Review  of  Heun’s  Method  (Deriva:on  from  Integra:on)  

Notice that the formula on the right hand side of (8.4) involves the yet to be determined value To estimate

or, for our case (8.5)

Substituting (8.5) into (8.4), the resulting formula is called Heun’s method, given as

(8.6)

Page 5: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Review  of  Heun’s  Method  (Deriva:on  from  Integra:on)  

In Heun’s method, at each step: (a)  the Euler’s (forward) method is used as a prediction, and

then, (b)  the trapezoidal rule is used to make a correction to obtain

the final value.

The general step for Heun’s method is

Predictor:

Corrector: (8.7)

Page 6: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Example    

Use Heun’s method to solve the IVP

Solution:

Compare solutions for

(1) For

we use to calculate

Page 7: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Example    

Thus, the corrector:

which we use to calculate

, the predictor:

Page 8: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Example    

xi yi yexact h = 0.5 h = 0.25 h = 0.125

0 1.0 1.0 1.0 1.0 0.125 0.943359 (0.0127%) 0.943239 0.25 0.898438 (0.1055%) 0.897717 (0.0252%) 0.897491 0.375 0.862406 (0.037%) 0.862087 0.5 0.84375 (0.8785%) 0.838074 (0.1999%) 0.836801 (0.0477%) 0.836402 0.75 0.814081 (0.2726%) 0.812395 (0.0649%) 0.811868 1 0.831055 (1.3986%) 0.822196 (0.3177%) 0.820213 (0.0758%) 0.819592 1.5 0.930511 (1.4623%) 0.920143 (0.3318%) 0.917825 (0.0791%) 0.917100 2 1.117587 (1.2639%) 1.106800 (0.2865%) 1.104392 (0.0683%) 1.103638 2.5 1.373115 (1.0004%) 1.362593 (0.2265%) 1.360248 (0.054%) 1.359514 3 1.682121 (0.7626%) 1.672269 (0.1725%) 1.670076 (0.0411%) 1.669390

Page 9: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

MATLAB  Implementa:ons  function [x,y] = HeunMethod(f,xinit,xend,yinit,h) % Number of iterationsN = (xend-xinit)/h; x = zeros(1, N);y = zeros(1, N); y(1) = yinit;x(1) = xinit; for i=1:N x(i+1) = x(i)+h; y0 = y(i) + feval(f,x(i),y(i))*h; pred1 = feval(f,x(i),y(i)); pred2 = feval(f,x(i+1),y0); y(i+1) = y(i) + h*(pred1+pred2)/2;end

function dydx = Example_HeunMethod(x,y) dydx = (x-y)/2; end

Page 10: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

MATLAB  Implementa:ons  

Page 11: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Runge-­‐Ku(a  Method  

Here we see that Heun's method is an improvement over the rather simple Euler’s (forward) method. Although the method uses Euler's method as a basis, it goes beyond it, it attempts to compensate for the Euler method's failure to take the curvature of the solution curve into account. Heun's method is one of the simplest of a class of methods called predictor-corrector algorithms. One of the most powerful predictor-corrector algorithms of all—one which is so accurate, that most computer packages designed to find numerical solutions for differential equations will use it by default— is the fourth order Runge-Kutta method.

Page 12: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Second-­‐Order  Runge-­‐Ku(a  Methods  The 2nd order Runge-Kutta method simulates the accuracy of the Taylor series method of order 2. Recall the Taylor series formula for

Where CT is a constant involving the third derivative of and the other terms in the series involve powers of for n > 3.

(8.8)

The derivatives must expressed in terms of and its partial derivatives. Recall that

(8.9)

Page 13: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Second-­‐Order  Runge-­‐Ku(a  Methods  Equation (8.9) can be differentiated using the chain rule for differentiating a function of two variables, for example:

then

Back to the equation (8.9),

Page 14: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Second-­‐Order  Runge-­‐Ku(a  Methods  Another notation for partial derivatives:

hence (8.10)

Substitute the derivatives (8.9) and (8.10) into the Taylor series (8.8):

(8.11)

Page 15: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Second-­‐Order  Runge-­‐Ku(a  Methods  For second order, equation (8.11) can be rewritten as a linear combination of two function values to express

where (8.12)

Next, we determine the values of A, B, P and Q.

(8.13)

Page 16: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Second-­‐Order  Runge-­‐Ku(a  Methods  Recall Taylor series for functions more than one variable (Lecture 1):

and use it to expand f1 in equation (8.13) to get

(8.14)

Page 17: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Second-­‐Order  Runge-­‐Ku(a  Methods  Then (8.14) is used in (8.12) to get the second-order Runge-Kutta expression for

(8.15)

or

Page 18: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Second-­‐Order  Runge-­‐Ku(a  Methods  Comparing similar terms in equations (8.11) and (8.15):

implies that

implies that

implies that

Page 19: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Second-­‐Order  Runge-­‐Ku(a  Methods  

The second-order Runge-Kutta method in (8.15) will have the same order of accuracy as the Taylor’s method in (8.11).

Now, there are 4 unknowns with only three equations, hence the system of equations (8.16) is undetermined, and we are permitted to choose one of the coefficients.

Hence, we require that A, B, P, and Q satisfy the relations

(8.16)

Case (i): Choose

This choice leads to

Page 20: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Second-­‐Order  Runge-­‐Ku(a  Methods  Substituting these values into equation (8.12) and (8.13) yields

Case (ii): Choose

This choice leads to

(8.17)

Substituting these values into equation (8.12) and (8.13) yields

(8.18)

Page 21: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Example  MATLAB implementations of 2nd order Runge-Kutta methods for IVP

Page 22: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Example  MATLAB implementations of 2nd order Runge-Kutta methods for IVP

Page 23: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Third-­‐Order  Runge-­‐Ku(a  Methods  

The general formula is

where

(8.19)

Page 24: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Fourth-­‐Order  Runge-­‐Ku(a  Methods  

The classical fourth-order Runge-Kutta method

where

(8.20)

Page 25: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Higher-­‐Order  Runge-­‐Ku(a  Methods  

(1) Butcher’s fifth-order Runge-Kutta method:

(8.21) where

Page 26: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Higher-­‐Order  Runge-­‐Ku(a  Methods  

(1) Butcher’s fifth-order Runge-Kutta method:

Page 27: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Higher-­‐Order  Runge-­‐Ku(a  Methods  

(2) Runge-Kutta-Fehlberg (RKF45) method Each step requires the use of the following six values

Page 28: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Higher-­‐Order  Runge-­‐Ku(a  Methods  

An approximation using a fourth-order Runge-Kutta method is given by:

(8.22)

Page 29: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Example  MATLAB implementations of 2nd order, 3rd order, and 4th order Runge-Kutta methods for IVP

and step size

The exact solution is

Page 30: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

h  =  0.2  

Page 31: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

h  =  0.1  

Page 32: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Precision  of  the  Runge-­‐Ku(a  Method  

Assume that y(x) is the solution of the IVP. If

approximations generated by the Runge-Kutta method of order 4, then

is the sequence of

In particular, the global error at the end of the interval will satisfy

Page 33: Runge&Ku(a*Methods* - Boston Universitypeople.bu.edu/andasari/courses/Fall2014/LectureNotes/Week4_Lecture8.pdf · HigherOrder* Runge&Ku(a*Methods* (2) Runge-Kutta-Fehlberg (RKF45)

Precision  of  the  Runge-­‐Ku(a  Method  

If approximations are computed using the step size h and h/2, we should have

The idea is that, if the step size in Runge-Kutta order 4 is reduced by a factor of ½, we can expect that the global error will be reduced by a factor of