6
PHY 301: MATH AND NUM TECH Contents Chapter 10: Numerical Techniques I. Integration A. Intro B. Euler Recall basic Predictor-Corrector C. Runge-Kutta 2

PHY 301: MATH AND NUM TECH Contents Chapter 10: Numerical Techniques I. Integration A.Intro B.Euler Recall basic Predictor-Corrector C. Runge-Kutta

Embed Size (px)

DESCRIPTION

PHY 301: MATH AND NUM TECH I. Numerical integration I. NUMERICAL INTEGRATION: B. Euler Methods B2. Predictor-Corrector Euler Method It is a refinement on the above. The problem with the above is that the value of the slope of the tangent to the graph at t n, is not a good estimate of the tangent in the interval t n, t n+1. Given that x n is accurate, x n+1 would be just as good if we could know the tangent of the cord from x n to x n+1 (see picture below). Although we can’t because we don’t know x n+1 (since it is obviously what we are trying to estimate) we can come up with an approximation for the value of that slope: Discretize it: The error made at each step is of order h 2. Calling x n the approximate value of x aftern iterations of the formula above we get: We start from our standard 1 st order diff eq: B1. Basic Euler Method

Citation preview

Page 1: PHY 301: MATH AND NUM TECH Contents Chapter 10: Numerical Techniques I. Integration A.Intro B.Euler  Recall basic  Predictor-Corrector C. Runge-Kutta

PHY

301:

MAT

H AN

D N

UM

TEC

H

Contents

Chapter 10: Numerical Techniques

I. IntegrationA. IntroB. Euler

Recall basic Predictor-Corrector

C. Runge-Kutta 2

Page 2: PHY 301: MATH AND NUM TECH Contents Chapter 10: Numerical Techniques I. Integration A.Intro B.Euler  Recall basic  Predictor-Corrector C. Runge-Kutta

PHY

301:

MAT

H AN

D N

UM

TEC

H

I. Num

erical integration

I. NUMERICAL INTEGRATION: A. Intro

IA. Intro In a very generic manner a 1st order differential equation can be written as: As we have seen in Ch6, higher order equations can also be written if this form by introducing more dimensions. For instance:

can be written as: that we then write in the form ,

yielding a set of coupled 1st order differential equations.

The case where the equations are linear was treated in chapter 6. In general, however, we can often expect to be a function too complicated to allow a closed form solution for x(t) and thus numerical integration is required! In this chapter we’ll briefly review the Euler method from ch2, and then proceed to present a significantly more accurate and efficient method, called the Runge-Kutta (RK) method. We present with some detail the 2nd order RK to understand the idea behind this integration method, but leave it to you to look up the most often used 4th order RK.

d,

dx t

f x tt

2

2

d d, 0

d dx x

f x tt t

ddd ,d

x yty y f x tt

ddx Axt

Page 3: PHY 301: MATH AND NUM TECH Contents Chapter 10: Numerical Techniques I. Integration A.Intro B.Euler  Recall basic  Predictor-Corrector C. Runge-Kutta

PHY

301:

MAT

H AN

D N

UM

TEC

H

I. Num

erical integration

I. NUMERICAL INTEGRATION: B. Euler Methods

B2. Predictor-Corrector Euler MethodIt is a refinement on the above. The problem with the above is that the value of the slope of the tangent to the graph at tn, is not a good estimate of the tangent in the interval tn , tn+1. Given that xn is accurate, xn+1 would be just as good if we could know the tangent of the cord from xn to xn+1 (see picture below). Although we can’t because we don’t know xn+1 (since it is obviously what we are trying to estimate) we can come up with an approximation for the value of that slope:

d,

dx t

f x tt

Discretize it:

Introduce a step size we get:

1

1

, ,n nn n

n n

x t x t x tf x t f x t t

t t t

1 ,n n n nx t x t hf x t t

The error made at each step is of order h2. Calling xn the approximate value of x aftern iterations of the formula above we get:

1 ,n n n nx x hf x t

We start from our standard 1st order diff eq:B1. Basic Euler Method

Page 4: PHY 301: MATH AND NUM TECH Contents Chapter 10: Numerical Techniques I. Integration A.Intro B.Euler  Recall basic  Predictor-Corrector C. Runge-Kutta

PHY

301:

MAT

H AN

D N

UM

TEC

H

I. Num

erical integration

I. NUMERICAL INTEGRATION: B. Euler Methods: B2. Predictor- Corrector (cont’d)

Page 5: PHY 301: MATH AND NUM TECH Contents Chapter 10: Numerical Techniques I. Integration A.Intro B.Euler  Recall basic  Predictor-Corrector C. Runge-Kutta

PHY

301:

MAT

H AN

D N

UM

TEC

H

I. Num

erical integration

I. NUMERICAL INTEGRATION: C. Runge-Kutta Methods

Runge Kutta Methods. Derivation of RK2

Since we can formally integrate to: or

Since we assume that we got to step n with , our problem is to figure out the integral of the function of f(x,t). The idea of RK of order L is to cut up the interval [tn ,tn+1] in L pieces and do a Taylor series expansion of f(x,t) around the boundaries of the L pieces. f(x,t) is then approximated in terms of a weighted average of these expansions. Let see in details how it works for RK2.Thus for RK2 we cut the step interval [tn ,tn+1] in 2 and then approximate [tn ,tn+1] by a Taylor series expansion around the middle of that interval at tn+1/2 =tn +h/2 where h= tn+1 -tn is the step size for the integration. Thus we get:

d,

dx t

f x tt

1

1 ,n

n

t

n n tx t x t dt f x t

1

1 ,n

n

t

n n tx t x t dt f x t

n nx x t

1/2

21/2 1/2 1/2, ( , ) ( ) ( )

n

n n nt t

dff x t f x t t t t Order hdt

Now we insert the above into our formal integration formula:

1

1/2

21 1/2 1/2 1/2( , ) ( ) ( )n

nn

t

n n n n ntt t

dfx t x t dt f x t t t t Order hdt

1 1 1

1/2

21 1/2 1/2 1/2( , ) ( ) ( )n n n

n n nn

t t t

n n n n nt t tt t

dfx t x t dt f x t t dt t t dt Order hdt

1 1 1

1/2

21 1/2 1/2 1/2( , ) ( ) ( )n n n

n n nn

t t t

n n n n nt t tt t

dfx t x t f x t t dt dt t t dt Order hdt

1

1/2

2 21 1/2 1/2 1/2

1( , ) ( ) ( )2

n

n n

t

n n n n nt t t

dfx t x t f x t t h t t t h Order hdt

Page 6: PHY 301: MATH AND NUM TECH Contents Chapter 10: Numerical Techniques I. Integration A.Intro B.Euler  Recall basic  Predictor-Corrector C. Runge-Kutta

PHY

301:

MAT

H AN

D N

UM

TEC

H

I. Num

erical integration

Computing the second term, remembering that: and that:

Which is a little messy of a calculation but ends up being zero from the fact that we integrate a function which is odd with respect to its midpoint.Since that second term thus integrates to zero we are left with:

12

1 1 1/22

( , )2

( , )

n n nn

n n nn

hx x f x t

x x h f x t

1

2 2 21/2

1 1 1 1 1( ) ( ) ( )( ) ( ) ( ) ( ) ( ) (2 ) ( ) 02 2 2 2 2 2 2 2 2

n

n

t

n n n n n n n n n n n n n nt

h h h ht t t t h t t h t t t t h t t h t t h t h h t h

1n nt t h 12 2nn

ht t

The only problem is that we don’t know and thus use yet again a Taylor series expansion, but this

time around tn to figure it out at tn+1/2=tn+h/2:

212

( , ) ( )2n n nn

hx x t f x t t Order h

1 12 2

( )n n

x x t

Which is accurate to order h2 included! So by just doubling the number of steps to compute xn+1/2 and xn+1 versus only xn we have squared the accuracy of our computation from h to h2: This is why RK is so powerful. And what allowed us the result, is the expansion around the midpoint point that gave us a vanishing h2 term. RK4 involves 2 more lines of code at tn+h/4 and tn+3h/4 but is accurate to h4 which is why RK4 is used so often for numerical integration.

31 1/2 1/2( , ) ( )n n n nx t x t f x t t h Order h

Now notice that using this in the boxed result, gives us again accuracy to order h2 included for the second term because f is multiplied by h in that result. So our final result is: