Docsity

Crank-Nicolson Method Review, Lecture notes of Mathematics for Computing

Partial preview of the text

Download Crank-Nicolson Method Review and more Lecture notes Mathematics for Computing in PDF only on Docsity!

and

Insulated Boundaries

Douglas Wilhelm Harder, M.Math. LEL

Department of Electrical and Computer Engineering

University of Waterloo

Waterloo, Ontario, Canada

ece.uwaterloo.ca

[email protected]

© 2012 by Douglas Wilhelm Harder. Some rights reserved.

Outline

This topic discusses numerical approximations to

solutions to the heat-conduction/diffusion equation:

  • Consider the Crank-Nicolson method for approximating the heat-

conduction/diffusion equation

  • This is an implicit method - Uses Matlab from Laboratories 1 and 2 - Unconditionally stable
  • Defines the characteristics of insulated boundaries
  • Implement insulated boundaries into the Crank-Nicolson method

Review

In Laboratory 1, you solved a boundary-value problem:

  • Given the finite-difference equation

d

u

k − 1

  • du

k

  • d

−

u

k + 1

= g(x

k

),

there are three unknowns:

u

k – 1

u

k

u

k + 1

  • This requires us to set up a system

of n – 2 linear equations which must be

solved

  • The boundary values give us u

and u

n

Review

In Laboratory 2, we used an explicit method:

  • Given the finite-difference equation
  • All the values on the right-hand side

are known, we need only evaluate this

for u

2, k + 1

through u

n − 1 , k + 1

 

, 1 , 1, , 1,

2

2

i k i k i k i k i k

t

u u u u u

h

   

x

The Crank-Nicolson Method

What happens if we focus on the point (x

i

, t

k + 1

)?

 

 

,

2

,

i k i k

i k

i k i k i k

i k

u u

u x t

t h

u u u

u x t

x h

 

These focus on (x

i

, t

k + 1

)

The Crank-Nicolson Method

This gives us the finite-difference equation

The linear equation now has:

One known u

i, k

  • Three unknowns u

i – 1,k + 1

, u

i,k + 1

, u

i + 1, k + 1

 

, 1 , 1, 1 , 1 1, 1

2

2

i k i k i k i k i k

t

u u u u u

h

   

The Crank-Nicolson Method

Given two equations, we can add them:

 

 

2

2

i k i k i k i k i k

i k i k i k i k i k

t

u u u u u

h

t

u u u u u

h

   

   

 

 

2 2 2

2

i k i k i k i k i k

i k i k i k

t

u u u u u

h

t

u u u

h

   

  

The Crank-Nicolson Method

First, substitute

i k i k i k i k i k

i k i k i k

u u r u u u

r u u u

2

t

r

h

The Crank-Nicolson Method

We now have a new finite-difference equation:

i k i k i k i k i k i k i k

ru r u ru u r u u u

Unknowns Knowns

The Crank-Nicolson Method

As we did in Laboratory 1, we could then write n

x

  • 2

equations

   

2 1 2 2

k k k k k k k

ru r u ru u r u u u

       

   

2, 1 3, 1 4, 1 3, 2, 3, 4,

2 1 2 2

k k k k k k k

ru r u ru u r u u u

       

   

2 1 2 2

k k k k k k k

ru r u ru u r u u u

       

   

2, 1 1, 1 , 1 1, 2, 1, ,

2 1 2 2

x x x x x x x

n k n k n k n k n k n k n k

ru r u ru u r u u u

       

   

2 1 2 2

x x x x x x x

n k n k n k n k n k n k n k

ru r u ru u r u u u

       

..

.

.

n

x

  • 2

Unknowns Knowns

The Crank-Nicolson Method

That is: u

1, k + 1

= a

bndry

(t

k + 1

)

u

n , k + 1

= b

bndry

(t

k + 1

)

x

   

2 1 2 2

k k k k k k k

ru r u ru u r u u u

       

   

2, 1 3, 1 4, 1 3, 2, 3, 4,

2 1 2 2

k k k k k k k

ru r u ru u r u u u

       

   

2 1 2 2

k k k k k k k

ru r u ru u r u u u

       

   

2, 1 1, 1 , 1 1, 2, 1, ,

2 1 2 2

x x x x x x x

n k n k n k n k n k n k n k

ru r u ru u r u u u

       

   

2 1 2 2

x x x x x x x

n k n k n k n k n k n k n k

ru r u ru u r u u u

       

..

.

.

Unknowns Knowns

Bring them to the right-hand side....

The Crank-Nicolson Method

We now have n

x

  • 2 linear equations and n

x

  • 2 unknowns

   

 

2, 1 3, 1 2, 1, 2, 3, bndry 1

2 1 2 2

k k k k k k k

r u ru u r u u u ra t

      

   

 

2, 1 1, 1 1, 2, 1, , bndry 1

2 1 2 2

x x x x x x

n k n k n k n k n k n k k

ru r u u r u u u rb t

       

   

2, 1 3, 1 4, 1 3, 2, 3, 4,

2 1 2 2

k k k k k k k

ru r u ru u r u u u

       

   

2 1 2 2

k k k k k k k

ru r u ru u r u u u

       

   

2 1 2 2

x x x x x x x

n k n k n k n k n k n k n k

ru r u ru u r u u u

       

..

.

.

Unknowns Knowns

The Crank-Nicolson Method

Note the structure of b :

   

 

 

 

 

 

2, 1, 2, 3, bndry 1

1, 2, 1, , bndry 1

2 2

2 2

2 2

2 2

2 2

x x x x

x x x x

k k k k

k k k k

k k k k

n k n k n k n k

n k n k n k n k

u r u u u ra t

u r u u u

u r u u u

u r u u u

u r u u u rb t

     

 

    

 

  

 

 

 

 

  

 

 

   

 

 

 

bndry 1

bndry 1 1, 2, 1, ,

2 2 2 2 2 2

x x x x

x x x x

k k k k

k

k k k k

k k k k

n k n k n k n k

k n k n k n k n k

u u u u

ra t

u u u u

u u u u

r

u u u u

rb t u u u u

       

   

 

 

     

      

      

    

   

 

   

    

 

     

 

     

diff

Approximating the Solution

Thus, given the initial state at time t

, we create a system

of equations with k = 1 to solve for u

through u

n – 1, 2

x