You are on page 1of 9

1

Crank Nicholson Difference Method

Ui-1,j Ui, j Ui+1, j

Ui-1, j Ui,j+1 Ui+1, j+1

k
λ= … (1)
ah2
Where, λ = 1, hence, k = ah2

λ (Ui+1, j+1 + Ui-1, j+1) – 2(λ+1) Ui, j+1 = 2(λ-1) Ui, j……λ (Ui+1, j + Ui-1, j) … (2)

The equation (1) above is the Crank Nicholson difference scheme. Substituting for λ, equation
(2) reduces to:
1
Ui, j+1 = [Ui-1, j+1 + Ui+1, j+1 + Ui-1, j + Ui+1, j] … (3)
4

Example 1

Using the Crank Nicholson method, solve the heat equation:

Ut = Uxx

d2 U du
= ; subject to: U(x, 0) = 100x (1-x)
dx2 dt

U (0, t) = U (1, t) = 0

t > 0, 0 < x < 1


1 1
compute U for 1 time step, h = and k =
4 64

Solution

Substituting in equation (1):


1
64 1
λ=
1 2
=
(1)(4) 4

substituting for λ in equation (2):

OKON JOHN | AKSU


2
Crank Nicholson Difference Method

1 1 1 1
(Ui+1, j+1 + Ui-1, j+1) – 2 ( + 1) Ui, j+1 = 2( − 1) Ui, j…… (Ui+1, j + Ui-1, j) … (4)
4 4 4 4
1 10 6 1
(Ui+1, j+1 + Ui-1, j+1) - (Ui, j+1) = - (Ui, j)…… (Ui+1, j + Ui-1, j) … (5)
4 4 4 4

Multiplying through by 4 we have:

(Ui+1, j+1 + Ui-1, j+1) – 10(Ui, j+1) = -6 (Ui, j) …… (Ui+1, j + Ui-1, j) … (6)

From figure 1 we deduce:

Ui-1, j Ui, j Ui+1, j


0 0 0

L M R

0 0 0
Ui-1, j+1 Ui, j+1 Ui+1, j+1
Figure 2.0
From figure 2.0 above we can rewrite equation (2) as follows:

λ(L+R) – 2(λ+1) M = 2(λ-1) TM – λ(TL+TR) … (7)

where,

M = Middle

L = Left

R = Right

TM = Top Middle

TL = Top Left

TR = Top Right

Solving:

At U (x, 0) = 100x (1-x)

U (0, 0) = 100(0) (1-0) = 0

At, U (0.25, 0) = 100(0.25) (1-0.25)

= 2.5 × 0.75 = 18.75

At, U (0.50, 0) = 100(0.50) (1-0.5)

= 50 × 0.5 = 25

OKON JOHN | AKSU


3
Crank Nicholson Difference Method

At, U (0.75, 0) = 100(0.75) (1-0.75)

= 75 × 0.25 = 18.75

From the calculated values above we can generate a table as shown below:

t/x 0 0.25 0.50 0.75 1.0


0 0 18.75 25 18.75 0
0.015 0 U1 U2 U3 0
Table 1.0
Solving for the unknowns (i.e. U1, U2, U3), from equation (7), solving for U1:
1 1 1 1
(L+R) – 2( +1) M = 2( -1) TM – (TL+TR) … (8)
4 4 4 4

(L+R) – 10M = - 6(TM) – (TL+TR) … (9)

Substituting from values in table 1.0 into equation (9):

(0+U) – 10(U1) = - 6(18.75) – (0+25)


1
U2 – 10U1 = - – 25
2.5

U2 – 10U1 = - 137.5 … (10)

Solving for U2:

(L+R) – 10M = - 6(TM) – (TL+TR)

(U1+U3) – 10(U2) = - 6(25) – (18.75+18.75)

U1 + U3 - 10U2 = - 150 – 37.5 = - 187.5 … (11)

Solving for U3:

(L+R) – 10M = - 6(TM) – (TL+TR)

(U2 + 0) – 10(U3) = - 6(18.75) – (25 + 0)

U2 – 10U3 = - 112.5 – 25 = - 137.5 … (12)

Solving simultaneously:

Multiply equation (11) by 10:

10U1 + 10U3 – 100U2 = - 187.5 … (13)

Equation (13) + equation (12):

10U1 – 99U2 = - 2012.5 … (14)

Equation (14) + equation (10):

-98U2 = - 2150

Therefore, U2 = 21.94

Substituting for U2 in equation (10):

21.94 – 10U1 = - 137.5

OKON JOHN | AKSU


4
Crank Nicholson Difference Method

−137.5−21.94
U1 = = 15.94
−10
Substituting for U1 and U2 in equation (11):

15.94 + U3 – 10(21.94) = - 187.5

Hence, U3 = 15.56

Therefore,

U1 = 15.94

U2 = 21.94

U3 = 15.56

Example 2

d2 u du
Solve by Crank Nicholson method,: - = 0; 0 ≤ x ≤ subject to the following constraints:
dx2 dt
U (0, t) = 0

U (1, t) = 0

U (x, 0) = 100x (1-x), h = 0.25 per step, k = ah2 (specific condition, λ = 1)

Solution

At h = 0.25, and λ = 1, therefore, k = ah2 = (1) (0.25)2 = 0.0625.

Also, from the constraints and step size, we can develop a table as shown below, similar to
what we had in the previous example:

t/x 0 0.25 0.50 0.75 1.0


0 0 18.75 25 18.75 0
0.0625 0 U1 U2 U3 0
Table 2.0
Solving for the unknowns (i.e. U1, U2, U3), from equation (7), solving for U1:

λ(L+R) – 2(λ+1) M = 2(λ-1) TM – λ(TL+TR)

substituting:

(1)(L+R) – 2(1+1) M = 2(1-1) TM – 1(TL+TR)

(L+R) – 4M = - 1(TL+TR) … (15)

(0+U2) – 4U1 = - 1(0+25)

U2 – 4U1 = - 25 … (16)

Solving for U2:

From equation (15):

(L+R) – 4M = - 1(TL+TR)

(U1+U3) – 4U2 = - (18.75+18.75)

OKON JOHN | AKSU


5
Crank Nicholson Difference Method

U1 + U3 - 4U2 = - 37.5 … (17)

Solving for U3:

(L+R) – 4M = - 1(TL+TR)

U2 + 0 – 4U3 = - 37.5

U2 – 4U3 = - 37.5 … (18)

Solving simultaneously:

From equation (16):

U2 – 4U1 = - 25

U2 = - 25 + 4U1 … (19)

substituting for U2 in equation (17):

U1 + U3 - 4U2 = - 37.5

U1 + U3 -4(- 25 + 4U1) = - 37.5

U1 + U3 + 100 – 16U1 = - 37.5

U3 – 15U1 = - 137.5 … (20)

multiply equation (20) by 4:

4U3 – 60U1 = - 550 … (21)

Equation (21) + equation (18):

-60U1 + U2 = - 550 – 37.5

-60U1 + U2 = - 587.5 … (22)

Substitute for U2 from equation (19) in equation (22):

-60U1 + U2 = - 587.5

-60U1 + (- 25 + 4U1) = - 587.5

-60U1 – 25 + 4U1 = - 587.5


− 562.5
U1 = = 10.04
−56
substitute for U1 in equation (19):

U2 = - 25 + 4U1

U2 = - 25 + 4U1

=- 25 + 4(10.04) = 15.04

Substitute for U2 in equation (18):

U2 – 4U3 = - 37.5

15.04 – 4U3 = - 37.5

OKON JOHN | AKSU


6
Crank Nicholson Difference Method

−52.54
U3 = = 13.135
−4
Therefore,

U1 = 10.04

U2 = 15.04

U3 = 13.135

Example 3

d2 u du
Solve by Crank Nicholson simplified formula: - = 0, with the following constraints:
dx2 dt
U (0, t) = 0

U (1, t) = 2t

U (x, 0) = 0

Take h = 0.25 for two time steps

Solution

At h = 0.25, and λ = 1, therefore, k = ah2 = (1) (0.25)2 = 0.0625.

From the constraints,

At U (1, t) = 2t (i.e. x = 1):

At U (1, t) = 2(0) = 0

For step 1:

At U (1, 0.0625) = 2(0.0625) = 0.125

For step 2:

At U (1, 0.125) = 2 (0.125) = 0.25

Also, at U (X, 0) = 0 (i.e. x = x): any value of x will give t = 0

From the above constraints, we can generate the table shown below:

t/x 0 0.25 0.50 0.75 1.0


0 0 0 0 0 0
0.0625 0 U1 U2 U3 0.125
0.125 0 U4 U5 U6 0.25
Table 3.0
Solving for the unknowns (i.e. U1, U2, U3), from equation (7), solving for U1:

λ(L+R) – 2(λ+1) M = 2(λ-1) TM – λ(TL+TR)

At λ = 1:

(L+R) – 4M = - (TL + TR)

Substituting:

OKON JOHN | AKSU


7
Crank Nicholson Difference Method

0 + U2 – 4U1 = - (0 + 0)

U2 – 4U1 = 0

U2 = 4U1 … (23)

Solving for U2:

From equation (15):

(L+R) – 4M = - (TL + TR)

U1 + U3 – 4U2 = - (0 + 0)

U1 + U3 – 4U2 = 0 … (24)

Solving for U3:

(L+R) – 4M = - (TL + TR)

U2 + 0.125 – 4U3 = - (0 + 0)

U2 – 4U3 = - 0.125 … (25)

Solving Simultaneously:

Substitute for U2 in equation (23):

U1 + U3 – 4(4U1) = 0

U1 – 16U1 + U3 = 0

-15U1 + U3 = 0 … (26)

Multiply equation (23) by 4:

-60U1 + 4U3 = 0 … (27)

Equation (27) + equation (25):

-60U1 + U2 = - 0.125 … (28)

Recall from equation (23), U2 = 4U1, substitute for U2 in equation (28):

-60U1 + 4U1 = - 0.125

-56U1 = - 0.125

U1 = 0.00223

Substitute for U1 in equation (23):

U2 = 4U1

U2 = 4(0.00223) = 0.00892

Substitute for U2 in equation (25):

0.00892 – 4U3 = - 0.125

-4U3 = - 0.125 - 0.00892

OKON JOHN | AKSU


8
Crank Nicholson Difference Method

−0.13392
U3 = = 0.03348
−4
From the calculated values, table 3.0 is updated as shown below:

t/x 0 0.25 0.50 0.75 1.0


0 0 0 0 0 0
0.0625 0 0.00223 0.00892 0.03348 0.125
0.125 0 U4 U5 U6 0.25
Table 3.0b
Solving for the unknowns (i.e. U4, U5, U6), from equation (15), solving for U4:

(L+R) – 4M = - (TL + TR)

(0 + U5) – 4U4 = - (0 + 0.00892)

U5 – 4U4 = - 0.00892 … (29)

Solving for U5:

(L+R) – 4M = - (TL + TR)

U4 + U6 – 4U5 = - (0.00223 + 0.03348)

U4 + U6 – 4U5 = - 0.03571 … (30)

Solving for U6:

(L+R) – 4M = - (TL + TR)

U5 + 0.25 – 4U6 = - (0.00892 + 0.125)

U5 + 0.25 – 4U6 = - 0.13392

U5 – 4U6 = - 0.38392 … (31)

Solving Simultaneously:

Equation (31) – equation (29):

-4U6 + 4U4 = - 0.375 … (32)

Multiply equation (30) by 4:

4U4 + 4U6 – 16U5 = - 0.14284 … (33)

Equation (33) + equation (32):

8U4 – 16U5 = - 0.51784 … (34)

From equation (29), U5 = - 0.00892 + 4U4, substitute for U5 in equation (34):

8U4 – 16(- 0.00892 + 4U4) = - 0.51784

8U4 – 64U4 = - 0.51784 – 0.14272

-56U4 = - 0.66056

U4 = 0.01179

OKON JOHN | AKSU


9
Crank Nicholson Difference Method

Substitute for U4 in equation (29):

U5 – 4(0.01179) = - 0.00892

U5 – 0.04718 = - 0.00892

U5 = 0.03826

Substitute for U5 in equation (31):

0.03826 – 4U6 = - 0.38392

-4U6 = - 0.38392 – 0.03826

-4U6 = - 0.42218

U6 = 0.10554

Therefore,

U1 = 0.00223

U2 = 0.00892

U3 = 0.03348

U4 = 0.01179

U5 = 0.03826

U6 = 0.10554

Hence, table 3.0b can be updated as shown below:

t/x 0 0.25 0.50 0.75 1.0


0 0 0 0 0 0
0.0625 0 0.00223 0.00892 0.03348 0.125
0.125 0 0.01179 0.03826 0.10554 0.25

Table 3.0c

OKON JOHN | AKSU

You might also like