numerical methods for partial differential equations caam 452 spring 2005 lecture 9 instructor: tim...

35
Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

Upload: rayna-fearing

Post on 14-Dec-2015

220 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

Numerical Methods for Partial Differential Equations

CAAM 452

Spring 2005

Lecture 9

Instructor: Tim Warburton

Page 2: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Today

• Change of plan – I will go through in detail how to solve homework 3

step by step.

Page 3: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Homework 3

Q1) Build a finite-difference solver for

Q1a) use your Cash-Karp Runge-Kutta time integrator from HW2 for time stepping

Q1b) use the 4th order central difference in space (periodic domain)

Q1c) perform a stability analysis for the time-stepping (based on visual inspection of the CK R-K stability region containing the imaginary axis)

Q1d) bound the spectral radius of the spatial operator

Q1e) choose a dt well in the stability region

Q1f) perform four runs with initial condition (use M=20,40,80,160) and compute maximum error at t=8

Q1g) estimate the accuracy order of the solution.

Q1h) extra credit: perform adaptive time-stepping to keep the local truncation error from time stepping bounded by a tolerance.

u uc

t x

24cos,0 , 0,2xu x e x

Page 4: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Q1a – Use Cash-Karp RK for Time-Stepping

• We will use a vector version of Cash-Karp:

• Where f is a vector valued function – in our case it will be a linear operator acting on a vector argument.

1

2 121

3 1 231 32

4 1 2 341 42 43

5 1 2 3 451 52 53 54

6 1 2 3 4 561 62 63 64 65

1 1 2 31 2 3 4

n

n

n

n

n

n

n n

k dtf u

k dtf u b k

k dtf u b k b k

k dtf u b k b k b k

k dtf u b k b k b k b k

k dtf u b k b k b k b k b k

u u c k c k c k c

4 5 65 6k c k c k

Page 5: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Where the b,c coefficients arehttp://www.library.cornell.edu/nr/bookcpdf/c16-2.pdf

c= 37/378 0 250/621 125/594 0 512/1771

0 0 0 0 0

1/5 0

3/40 9/40 0

3/10 -9/10 6/5 0

-11/54 5/2 -70/27 35/27 0

1631/55296 175/512 575/13824 44275/110592 253/4096 0

b

Provided in cashkarp.m on the web site.Original paper at:

http://portal.acm.org/citation.cfm?id=79507&coll=GUIDE&dl=GUIDE&CFID=38381912&CFTOKEN=60548034

Page 6: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Homework 3

Q1) Build a finite-difference solver for

Q1a) use your Cash-Karp Runge-Kutta time integrator from HW2 for time stepping

Q1b) use the 4th order central difference in space (periodic domain)

Q1c) perform a stability analysis for the time-stepping (based on visual inspection of the CK R-K stability region containing the imaginary axis)

Q1d) bound the spectral radius of the spatial operator

Q1e) choose a dt well in the stability region

Q1f) perform four runs with initial condition (use M=20,40,80,160) and compute maximum error at t=8

Q1g) estimate the accuracy order of the solution.

Q1h) extra credit: perform adaptive time-stepping to keep the local truncation error from time stepping bounded by a tolerance.

u uc

t x

24cos,0 , 0,2xu x e x

Page 7: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Recall: 4th Order Central Difference Scheme

4 2 1 1 2

18 8

12 m m m mmv v v v v

dx

The fourth order central difference derivative acts on any vector and gives the following value for each entry of a result vector:

Where the increments on the indexing is done modulo M.Since we will use this operator repeatedly I made a function

Page 8: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Code

• Each time step consists of evaluating the 6 intermediate vectors k1,k2,..,k6

• And piecing them together.

• Notice – here I set up u at the start as a vector, and delta4 accepts a vector (and dx) as arguments and returns a vector.

• i.e. each of k1,k2,..,k6 is a vector.

Page 9: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Alternate Code

• I could also have used loops

• Note: u is a row vector of length M so the k’s are a matrix of size 6 x M

Page 10: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Homework 3

Q1) Build a finite-difference solver for

Q1a) use your Cash-Karp Runge-Kutta time integrator from HW2 for time stepping

Q1b) use the 4th order central difference in space (periodic domain)

Q1c) perform a stability analysis for the time-stepping (based on visual inspection of the CK R-K stability region containing the imaginary axis)

Q1d) bound the spectral radius of the spatial operator

Q1e) choose a dt well in the stability region

Q1f) perform four runs with initial condition (use M=20,40,80,160) and compute maximum error at t=8

Q1g) estimate the accuracy order of the solution.

Q1h) extra credit: perform adaptive time-stepping to keep the local truncation error from time stepping bounded by a tolerance.

u uc

t x

24cos,0 , 0,2xu x e x

Page 11: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Cash-Karp

• The Cash-Karp Runge-Kutta integrator in our case is:

• Notice, we do not need the time component on the right hand side, because our finite-difference right hand side is independent of time.

1

2 121

3 1 231 32

4 1 2 341 42 43

5 1 2 3 451 52 53 54

6 1 2 3 4 561 62 63 64 65

1 1 2 3 4 5 61 2 3 4 5 6

n

n

n

n

n

n

n n

k dtf u

k dtf u b k

k dtf u b k b k

k dtf u b k b k b k

k dtf u b k b k b k b k

k dtf u b k b k b k b k b k

u u c k c k c k c k c k c k

Page 12: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Linear Stability Analysis

• We achieve the linear stability analysis by assuming f is linear in u: f u u

1

2 121

3 1 231 32

4 1 2 341 42 43

5 1 2 3 451 52 53 54

6 1 2 3 4 561 62 63 64 65

1 1 2 3 4 5 61 2 3 4 5 6

n

n

n

n

n

n

n n

k dtu

k dt u b k

k dt u b k b k

k dt u b k b k b k

k dt u b k b k b k b k

k dt u b k b k b k b k b k

u u c k c k c k c k c k c k

Page 13: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

cont

• We replace mu*dt with nu

1

2 121

3 1 231 32

4 1 2 341 42 43

5 1 2 3 451 52 53 54

6 1 2 3 4 561 62 63 64 65

1 1 2 3 4 5 61 2 3 4 5 6

n

n

n

n

n

n

n n

k u

k u b k

k u b k b k

k u b k b k b k

k u b k b k b k b k

k u b k b k b k b k b k

u u c k c k c k c k c k c k

Page 14: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

cont

• We wish to remove all the intermediate variables and express the scheme in a one-step form like:

• Where the multiplier function pi(nu) is a 6th order polynomial in nu.

• It is certainly possible to find all the coefficients of this polynomial by hand but a little messy.

• We can take a short cut – assuming Cash-Karp is actually a 5th order scheme as claimed we know that the first 6 terms of the polynomial multiplier must be the first 6 terms of the Taylor series for

1n nu u

e

Page 15: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

cont

• So we know that:

• Where C is to be determined.

• However, looking at the definition of the stages we see that there is only one contribution to the 6th order term:

• So

1 2 3 4 5 61 1 1 1 11

1! 2! 3! 4! 5!C

66 65 54 43 32 21c b b b b b

1 2 3 4 5 66 65 54 43 32 21

1 1 1 1 11

1! 2! 3! 4! 5!c b b b b b

Page 16: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Stability Condition

• We need to plot the stability region, so we determine the margin of stability by finding nu such that

• The curve of points in the (root) complex plane with magnitude 1 can be parameterized in theta by

• So for each theta in [0,2pi) we seek the corresponding nu such that:

1 2 3 4 5 66 65 54 43 32 21

1 1 1 1 11 1

1! 2! 3! 4! 5!c b b b b b

ie

1 2 3 4 5 66 65 54 43 32 21

1 1 1 1 11

1! 2! 3! 4! 5!ic b b b b b e

Page 17: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Matlab roots Command

• The matlab roots command can be used to find roots of a polynomial.

• If the polynomial is say:

• Then construct a vector of coefficients (highest order first):

• And invoke: roots(a)• A vector of the roots (if any) of the polynomial will

be returned.

21 2 3x a a x a x

3 2 1, ,a a a a

Page 18: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Adapting RKabstab.m

• So I took the routine from the class web page and modified it slightly

• I hard coded it to use the multiplier polynomial for the Cash-Karp

• I changed the plotting to use a scatter plot

Page 19: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Absolute Stability for Cash-Karp

• This is a classic picture.

• What is interesting is that it does not convincingly cover the imaginary axis!.

Page 20: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

On The Imaginary Axis

Here I used Matlab’s polyval to evaluate themultiplier polynomial for nu on the imaginary axis.Conclusion – the absolute stability region is justto the left of the imaginary axis (not a big issue here)

Page 21: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Homework 3

Q1) Build a finite-difference solver for

Q1a) use your Cash-Karp Runge-Kutta time integrator from HW2 for time stepping

Q1b) use the 4th order central difference in space (periodic domain)

Q1c) perform a stability analysis for the time-stepping (based on visual inspection of the CK R-K stability region containing the imaginary axis)

Q1d) bound the spectral radius of the spatial operator

Q1e) choose a dt well in the stability region

Q1f) perform four runs with initial condition (use M=20,40,80,160) and compute maximum error at t=8

Q1g) estimate the accuracy order of the solution.

Q1h) extra credit: perform adaptive time-stepping to keep the local truncation error from time stepping bounded by a tolerance.

u uc

t x

24cos,0 , 0,2xu x e x

Page 22: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Q1d) Bound the spectral radius of the derivative operator

• All the eigenvalues of the 4th order central difference are on the imaginary axis, with values (recall from Lecture 6):

• So the gotcha is that there is no dt such that the eigenvalues*dt are all exactly inside the stability region.

• However, we will estimate the largest eigenvalue and make an assumption..

8sin sin 26m m m

icdx

Page 23: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Q1d) continued

2

2

-1

8sin sin 26

8cos 2cos 26

critical points for which satisfy:

0 8cos 2cos 2

=8cos 2 2cos 1

=-4cos 8cos 2

8 64 32 3. . cos 1

8 2

3. . = cos (1- ) 1.37222...

2 m

icdx

d icd dx

i e

ci e

dx

We can estimate the largestmagnitude eigenvalue directly.

Page 24: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Homework 3

Q1) Build a finite-difference solver for

Q1a) use your Cash-Karp Runge-Kutta time integrator from HW2 for time stepping

Q1b) use the 4th order central difference in space (periodic domain)

Q1c) perform a stability analysis for the time-stepping (based on visual inspection of the CK R-K stability region containing the imaginary axis)

Q1d) bound the spectral radius of the spatial operator

Q1e) choose a dt well in the stability region

Q1f) perform four runs with initial condition (use M=20,40,80,160) and compute maximum error at t=8

Q1g) estimate the accuracy order of the solution.

Q1h) extra credit: perform adaptive time-stepping to keep the local truncation error from time stepping bounded by a tolerance.

u uc

t x

24cos,0 , 0,2xu x e x

Page 25: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Q1e)

• Since we are only integrating for 8 periods let’s choose a reasonable maximum |nu|<=1

• So for close to absolute (linear) stability

• Implies that we can choose:

• i.e. the time step restriction is:

• We can further reduce the right hand side of the inequality to reduce marginal growth.

1.37222...m

cdx

1.37222 1cdtdx

1.37222dx

dtc

Page 26: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Homework 3

Q1) Build a finite-difference solver for

Q1a) use your Cash-Karp Runge-Kutta time integrator from HW2 for time stepping

Q1b) use the 4th order central difference in space (periodic domain)

Q1c) perform a stability analysis for the time-stepping (based on visual inspection of the CK R-K stability region containing the imaginary axis)

Q1d) bound the spectral radius of the spatial operator

Q1e) choose a dt well in the stability region

Q1f) perform four runs with initial condition (use M=20,40,80,160) and compute maximum error at t=8

Q1g) estimate the accuracy order of the solution.

Q1h) extra credit: perform adaptive time-stepping to keep the local truncation error from time stepping bounded by a tolerance.

u uc

t x

24cos,0 , 0,2xu x e x

Page 27: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Q1f: Test Runs

• I already set up this initial condition for the web demos:

• I modified the testrig.m file to call the centraldifference4CKRK54.m file

• It looks like reasonable 4th order convergence..

• We examine the error ratios to be more certain

T=4

Page 28: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Homework 3

Q1) Build a finite-difference solver for

Q1a) use your Cash-Karp Runge-Kutta time integrator from HW2 for time stepping

Q1b) use the 4th order central difference in space (periodic domain)

Q1c) perform a stability analysis for the time-stepping (based on visual inspection of the CK R-K stability region containing the imaginary axis)

Q1d) bound the spectral radius of the spatial operator

Q1e) choose a dt well in the stability region

Q1f) perform four runs with initial condition (use M=20,40,80,160) and compute maximum error at t=8

Q1g) estimate the accuracy order of the solution.

Q1h) extra credit: perform adaptive time-stepping to keep the local truncation error from time stepping bounded by a tolerance.

u uc

t x

24cos,0 , 0,2xu x e x

Page 29: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Q1g) Estimate Order of Accuracy of Solution

M Max error at t=4 Order of accuracy

20 0.44353855151728

40 0.12852934806853 1.79

80 0.02040188007649 2.66

160 0.00134076263509 3.93

320 0.00008319425374 4.01

Cool – asymptotically it looks like a fourth order code (in space)

Page 30: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Homework 3

Q1) Build a finite-difference solver for

Q1a) use your Cash-Karp Runge-Kutta time integrator from HW2 for time stepping

Q1b) use the 4th order central difference in space (periodic domain)

Q1c) perform a stability analysis for the time-stepping (based on visual inspection of the CK R-K stability region containing the imaginary axis)

Q1d) bound the spectral radius of the spatial operator

Q1e) choose a dt well in the stability region

Q1f) perform four runs with initial condition (use M=20,40,80,160) and compute maximum error at t=8

Q1g) estimate the accuracy order of the solution.

Q1h) extra credit: perform adaptive time-stepping to keep the local truncation error from time stepping bounded by a tolerance.

u uc

t x

24cos,0 , 0,2xu x e x

Page 31: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Q1h) Estimating the Local Truncation Error

• Given the k vectors we can also construct a lower order (4th order in time) approximation to the updated solution:

• Then we can ball park what the time step should be:

1 * 1 * 2 * 3 * 4 * 5 * 61 2 3 4 5 6

n nu u c k c k c k c k c k c k

0.24

5 4min

rk

est rk rk

tol udt dt

u u

Page 32: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Q1h) Code

Form alternative embeddedfourth order approximation

Estimate reasonable dt

Check to see if we shouldreduce time step.

Modify last time step to landon EndTime

Page 33: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Q1h) Testing

• I started with a fairly large time step and let the code adjust itself

M Max error at t=4 Order of accuracy

20 0.44353855318971

40 0.12852934719014 1.79

80 0.02040190480104 2.66

160 0.00134075190765 3.93

320 0.00008319462183 4.01

These are pretty much unchanged from before.

Page 34: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Q1h) Adaptive Time Stepping(started with dt=100*dx)

Q)

Why does it take moretime steps for theLower resolution runs?

Page 35: Numerical Methods for Partial Differential Equations CAAM 452 Spring 2005 Lecture 9 Instructor: Tim Warburton

CAAM 452 Spring 2005

Note on the Cash-Karp RK

• Check out:• http://www.math.sfu.ca/~cbm/mscthesis/cbm-mscthesis.ps.gz

• There is an interesting treatment of RK schemes, with the idea of parameterizing embedded RK schemes (n+1 stage, n’th order) by choosing the coefficient in the multiplier directly.

• Increasing this parameter a little will make sure that at least part of the imaginary axis is inside the absolute stability region.