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

Post on 04-Jan-2016

218 views 3 download

transcript

Programming assignment #2Solving 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

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

Last lecture we will looked at three methods

• Forward Difference method (explicit)

• Backward difference method (implicit)

• Crank-Nicolson method (implicit)

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

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

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

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

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

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

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?

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.

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

Review: Vector Norms

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

||||||||||

00||||

0||||

yxyx

xx

xx

x

Review: Common Vector Norms

n

ii

ini

n

ii

xxl

xxl

xxl

111

1

2/1

1

222

||||:||

||max||:||

||:||

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

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

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||||

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

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

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

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

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

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

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

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.

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

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