+ All Categories
Home > Documents > Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for...

Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for...

Date post: 04-Jan-2016
Category:
Upload: merryl-black
View: 218 times
Download: 3 times
Share this document with a friend
27
Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones
Transcript
Page 1: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Programming assignment #2Solving a parabolic PDE using finite differences

Numerical Methods for PDEs Spring 2007

Jim E. Jones

Page 2: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

The Problem

lxxfxu

ttlutu

tlxtxx

utx

t

u

0),()0,(

0,0),(),0(

0,0),,(),(2

22

Reference: Burden and Faires, Numerical Analysis, Ch12

Page 3: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

The Problem

lxxfxu

ttlutu

tlxtxx

utx

t

u

0),()0,(

0,0),(),0(

0,0),,(),(2

22

Reference: Burden and Faires, Numerical Analysis, Ch12

PDE

Boundary conditions

Initial conditions

Page 4: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Last lecture we will looked at three methods

• Forward Difference method (explicit)

• Backward difference method (implicit)

• Crank-Nicolson method (implicit)

Page 5: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Time stepping formula

Forward Difference method

2

2

h

kr

)(2

1 ,1.122

,2

2

1, jijijiji wwh

kw

h

kw

i

j

h

k

Let

)),21(,(

1

rrrtridiagB

wBw jj

Page 6: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Time stepping formula

Backward Difference Method

)),21(,(

1

rrrtridiagA

wwA jj

1,,12

2

,12

2

,2

2

21

jijijiji ww

h

kw

h

kw

h

k

i

j

h

k

2

2

h

kr

Let

Page 7: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Time stepping formula

Crank-Nicolson Method

022

2 2

1,11,1,1

2

,1,,12

1,,

h

www

h

www

k

ww jijijijijijijiji

i

j

h

k

2),1(,

2

2),1(,

2

1

rr

rtridiagB

rr

rtridiagA

wBwA jj

Page 8: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Time stepping formula

All Methods

111

1

jjjjj wTwBAwwBwA

1 jj wBwA

Time stepping corresponds to matrix multiplication

Approximations are generated by repeated application of T

0wTw kk

Page 9: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Approximations are generated by repeated application of T

If the initial conditions are perturbed, the perturbed approximation is

And their difference is

Stability

0wTw kk

)( 0

wTz kk

k

kk Twz

Page 10: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Following the material from ODEs we will say that a numerical method is stable if perturbations in the initial conditions give rise to perturbations in the computed solution that do not grow without bound.

We want dk to be bounded for all k.

Stability

kkkk Twzd

Page 11: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Following the material from ODEs we will say that a numerical method is stable if perturbations in the initial conditions give rise to perturbations in the computed solution that do not grow without bound.

We want dk to be bounded for all k.

Stability

kkkk Twzd

What properties of the matrix T do we need to guarantee dk doesn’t grow without bound?

Page 12: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Following the material from ODEs we will say that a numerical method is stable if perturbations in the initial conditions give rise to perturbations in the computed solution that do not grow without bound.

We want dk to be bounded for all k.

Stability

kkkk Twzd

We need the right analogue of absolute value which is what we had for the scalar case in the ODE slides.

Page 13: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

A vector norm is a function ||x|| from Rn to R with the following properties:

Review: Vector Norms

||||||||||||

||||||||||

00||||

0||||

yxyx

xx

xx

x

Page 14: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Review: Common Vector Norms

n

ii

ini

n

ii

xxl

xxl

xxl

111

1

2/1

1

222

||||:||

||max||:||

||:||

Page 15: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

A matrix norm is a function ||A|| from the set of n x n matrices to R with the following properties:

Review: Matrix Norms

||||||||||||

||||||||||||

||||||||||

00||||

0||||

BAAB

BABA

AA

AA

A

Page 16: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Any vector norm ||x|| defines a corresponding matrix norm via:

And for this natural, matrix norm and its corresponding vector norm we have the following inequality

Review: Natural Matrix Norms

||||max||||1||||

xAAx

|||||||||||| xAxA

Page 17: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

The infinity norm of a matrix is the maximum row sum of the absolute values of its entries.

The one norm of a matrix is the maximum column sum of the absolute values of its entries.

Review: Common Natural Matrix Norms

n

jij

niaA

11

||max||||

n

iij

njaA

11

1 ||max||||

Page 18: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

The spectral radius (A) of a matrix is the largest eigenvalue in absolute value

The two norm of a matrix is related to the spectral radius

and if A is symmetric

Review: Spectral Radius and Two Norm

||max)( xxA

A

2/12 )]([|||| AAA t

)(|||| 2 AA

Page 19: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Following the material from ODEs we will say that a numerical method is stable if perturbations in the initial conditions give rise to perturbations in the computed solution that do not grow without bound.

Stability

||||||||||||||||||||

kk

k

kkkk

TTd

Twzd

We need conditions to guarantee

1|||| T

Page 20: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Stability of Forward Differences using infinity norm.

|21|2||||

)21(00

)21(00

0)21(00

00)21(0

00)21(

00)21(

rrT

rr

rrr

rrr

rrr

rrr

rr

BT

Td kk

2

2

h

kr

Page 21: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Stability of Forward Differences using infinity norm.

|21|2|||| rrT 2

2

h

kr

114)21(2|21|2|||| rrrrrT

• If r > ½

Unstable

•Else

Stable

1)21(2|21|2|||| rrrrT

Page 22: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Stability of Forward Differences using two norm.

)(||||

)21(00

)21(00

0)21(00

00)21(0

00)21(

00)21(

2 AT

rr

rrr

rrr

rrr

rrr

rr

BT

Td kk

2

2

h

kr

Page 23: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Eigenvalues and Eigenvectors on nxn matrix T

)21(00

)21(00

0)21(00

00)21(0

00)21(

00)21(

rr

rrr

rrr

rrr

rrr

rr

BT

1sin)(

,...,2,1,)1(2

sin41 2

n

imv

nmn

mr

im

m

Page 24: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Stability requires spectral radius bounded by one

1|)1(2

sin41|max)( 2

1

n

mrT

nm

• If r > ½Unstable

•ElseStable

Same result as infinity norm

Page 25: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Assignment #2

• Forward Difference method (explicit)

• Backward difference method (implicit)

• Crank-Nicolson method (implicit)

lxxfxu

ttlutu

tlxtxx

utx

t

u

0),()0,(

0,0),(),0(

0,0),,(),(2

22

Assignment #2 will is due Wednesday Feb 21. You will code up these three methods for a particular problem and look at accuracy and stability issues.

Page 26: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

PDE solution is:

The Burden and Faires text contains results for this example

Assignment #2

lxxfxu

ttlutu

tlxtxx

utx

t

u

0),()0,(

0,0),(),0(

10,0),,(),(2

22

)sin()(,1,1 xxfl

)sin(),(2

xetxu t

Page 27: Programming assignment #2 Solving a parabolic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.

Your job is to experiment with different values of h and k. Do your best to investigate numerically some of the issues we’ve talked about in the lecture.

• Stability: Run at least two problems with forward differences. One that satisfies the stability condition and one that does not. Comment on your observations. We’ve not seen it yet, but the other two methods are unconditionally stable.

•Convergence: Backward and Forward differencing has truncation error O(k+h2). Crank-Nicolson is O(k2+h2). Calculate the errors you see and comment on how they agree, or not, with these truncation error results.

•Comparison: Comment on the relative strengths and weaknesses of the three methods.

Assignment #2


Recommended