Professional Documents
Culture Documents
The Crank-Nicolson Method Insulated Boundaries: Douglas Wilhelm Harder, M.Math. LEL
The Crank-Nicolson Method Insulated Boundaries: Douglas Wilhelm Harder, M.Math. LEL
and
Insulated Boundaries
ece.uwaterloo.ca
dwharder@alumni.uwaterloo.ca
Outline
2
The Crank-Nicolson Method
3
The Crank-Nicolson Method
Review
4
The Crank-Nicolson Method
Review
5
The Crank-Nicolson Method
Review
6
The Crank-Nicolson Method
7
The Crank-Nicolson Method
8
The Crank-Nicolson Method
t
ui ,k 1 ui ,k
h 2 u
i 1, k 2ui ,k ui 1,k
9
The Crank-Nicolson Method
t
ui ,k 1 ui ,k
h 2 u
i 1, k 2ui , k ui 1, k
t
+ ui , k 1 ui , k 2 ui 1, k 1 2ui , k 1 ui 1, k 1
h
t
2ui ,k 1 2ui ,k 2 ui 1,k 2ui ,k ui 1,k
h
t
2 ui 1,k 1 2ui ,k 1 ui 1, k 1
h
10
The Crank-Nicolson Method
11
The Crank-Nicolson Method
12
The Crank-Nicolson Method
Unknowns Knowns
13
The Crank-Nicolson Method
runx 3,k 1 2 1 r unx 2,k 1 runx 1,k 1 2unx 2,k r unx 3,k 2unx 2,k unx 1,k
runx 2,k 1 2 1 r unx 1,k 1 runx ,k 1 2unx 1,k r u nx 2, k 2unx 1,k unx ,k
Unknowns Knowns
14
The Crank-Nicolson Method
15
The Crank-Nicolson Method
16
The Crank-Nicolson Method
Unknowns Knowns
17
The Crank-Nicolson Method
20
The Crank-Nicolson Method
21
The Crank-Nicolson Method
Given the initial state at time t2, we will create the system
of equations with k = 2 to solve for u2, 3 through unx – 1, 3
22
The Crank-Nicolson Method
23
The Crank-Nicolson Method
24
The Crank-Nicolson Method
25
The Crank-Nicolson Method
where
kappa the diffusivity coefficient
x_rng the space range [a, b]
nx the number of points into which we will divide [a, b]
t_rng the time interval [t0, tfinal]
nt the number of points into which we will divide [t0, tfinal]
u_init a function handle giving the initial state uinit:[a, b] → R
u_bndry a function handle giving the two boundary conditions
abndry t
where ubndry t
bbndry t
ubndry:[t0, tfinal] → R2
26
The Crank-Nicolson Method
t
Never-the-less, if 2
0.5 , there may be decaying
h
osillations
27
The Crank-Nicolson Method
28
The Crank-Nicolson Method
Step 2: Initialization
nt
uinit x1 abndry t2 abndry t3 abndry t4 abndry t5 abndry t6 abndry t7 abndry t8 abndry t9 abndry t10 abndry t11 abndry t12
uinit x2 ? ? ? ? ? ? ? ? ? ? ?
uinit x3 ? ? ? ? ? ? ? ? ? ? ?
uinit x4 ? ? ? ? ? ? ? ? ? ? ?
nx uinit x5 ? ? ? ? ? ? ? ? ? ? ?
uinit x6 ? ? ? ? ? ? ? ? ? ? ?
uinit x7 ? ? ? ? ? ? ? ? ? ? ?
uinit x8 ? ? ? ? ? ? ? ? ? ? ?
uinit x9 bbndry t2 bbndry t3 bbndry t4 bbndry t5 bbndry t6 bbndry t7 bbndry t8 bbndry t9 bbndry t10 bbndry t11 bbndry t12
29
The Crank-Nicolson Method
Step 3: Solving
nt
uinit x1 abndry t2 abndry t3 abndry t4 abndry t5 abndry t6 abndry t7 abndry t8 abndry t9 abndry t10 abndry t11 abndry t12
uinit x2 ? ? ? ? ? ? ? ? ? ? ?
uinit x3 ? ? ? ? ? ? ? ? ? ? ?
uinit x4 ? ? ? ? ? ? ? ? ? ? ?
nx uinit x5 ? ? ? ? ? ? ? ? ? ? ?
uinit x6 ? ? ? ? ? ? ? ? ? ? ?
uinit x7 ? ? ? ? ? ? ? ? ? ? ?
uinit x8 ? ? ? ? ? ? ? ? ? ? ?
uinit x9 bbndry t2 bbndry t3 bbndry t4 bbndry t5 bbndry t6 bbndry t7 bbndry t8 bbndry t9 bbndry t10 bbndry t11 bbndry t12
30
The Crank-Nicolson Method
Step 3: Solving
31
The Crank-Nicolson Method
32
The Crank-Nicolson Method
Examples
33
The Crank-Nicolson Method
Examples
[xs, ts, Us] = crank_nicolson1d( 1.5, [0 1], 6, [0 1], 21, @u3a_init, @u3a_bndry );
mesh( ts, xs, Us )
t
1.875
h2
34
The Crank-Nicolson Method
Examples
[xs, ts, Us] = crank_nicolson1d( 1.5, [0 1], 41, [0 1], 11, @u3a_init, @u3a_bndry );
mesh( ts, xs, Us )
t
240
h2
35
The Crank-Nicolson Method
Examples
[xs, ts, Us] = crank_nicolson1d( 1.5, [0 1], 41, [0 1], 41, @u3a_init, @u3a_bndry );
mesh( ts, xs, Us )
t
60
h2
36
The Crank-Nicolson Method
Examples
[xs, ts, Us] = crank_nicolson1d( 1.5, [0 1], 21, [0 1], 301, @u3a_init, @u3a_bndry );
mesh( ts, xs, Us )
t
2
h2
37
The Crank-Nicolson Method
Examples
38
The Crank-Nicolson Method
Examples
[x3b, t3b, U3b] = crank_nicolson1d( 0.25, [0 1], 11, [0 1], 11, @u3b_init, @u3b_bndry );
mesh( t3b, x3b, U3b );
frames3b = animate( U3b );
frames2gif( frames3b, 'plot3b.i.gif' ); t
2.5
h2
39
The Crank-Nicolson Method
Examples
[x3b, t3b, U3b] = crank_nicolson1d( 0.25, [0 1], 41, [0 1], 161, @u3b_init, @u3b_bndry );
mesh( t3b, x3b, U3b );
frames3b = animate( U3b );
t
frames2gif( frames3b, 'plot3b.ii.gif' );
2.5
h2
40
The Crank-Nicolson Method
Insulated Boundaries
41
The Crank-Nicolson Method
Terminology
42
The Crank-Nicolson Method
Insulated Boundaries
0 oC 100 oC
43
The Crank-Nicolson Method
Insulated Boundaries
0 oC 100 oC
44
The Crank-Nicolson Method
Insulated Boundaries
0 oC 100 oC
45
The Crank-Nicolson Method
Insulated Boundaries
0 oC 100 oC
46
The Crank-Nicolson Method
Insulated Boundaries
0 oC 42 oC
47
The Crank-Nicolson Method
Insulated Boundaries
0 oC 0 oC
48
The Crank-Nicolson Method
Insulated Boundaries
49
The Crank-Nicolson Method
Insulated Boundaries
50
The Crank-Nicolson Method
Insulated Boundaries
are
u a 2h, tk 1 4u a h, tk 1 3u a, tk 1
0
2h
3u b, tk 1 4u b h, tk 1 u b 2h, tk 1
0
2h
51
The Crank-Nicolson Method
Insulated Boundaries
4 1 4 1
u1,k 1 u2,k 1 u3,k 1 unx ,k 1 unx 1,k 1 unx 2,k 1
3 3 3 3
52
The Crank-Nicolson Method
Insulated Boundaries
runx 2, 1
2 1 r unx 1,k 1 runx ,k 1 2unx 1,k r unx 2,k 2unx 1,k unx ,k
53
The Crank-Nicolson Method
Insulated Boundaries
54
The Crank-Nicolson Method
Insulated Boundaries
2
ru3, k 1 2u2, k r u1, k 2u2, k u3, k
2
2 r 2,k 1
u
3 3
2
2
runx 2,
3
1
2
r unx 1,k 1 2unx 1,k r unx 2,k 2unx 1,k unx ,k
3
55
The Crank-Nicolson Method
Insulated Boundaries
56
The Crank-Nicolson Method
Insulated Boundaries
57
The Crank-Nicolson Method
Insulated Boundaries
58
The Crank-Nicolson Method
Insulated Boundaries
59
The Crank-Nicolson Method
Insulated Boundaries
function u = u3c_bndry(t)
u = [0*t + NaN;
0*t + 2];
end
60
The Crank-Nicolson Method
Insulated Boundaries
61
The Crank-Nicolson Method
Insulated Boundaries
t
2
1.1719
h
62
The Crank-Nicolson Method
Insulated Boundaries
Insulated Boundaries
Insulated Boundaries
4 1
Now we reuse the formula: u1,2 u2,2 u3,2
3 3
1 1.0010 NaN NaN NaN NaN NaN NaN NaN
1 1.0070 0 0 0 0 0 0 0
1 1.0250 0 0 0 0 0 0 0
1 1.0858 0 0 0 0 0 0 0
1 1.2929 0 0 0 0 0 0 0
1 2 2 2 2 2 2 2 2
Insulated Boundaries
Insulated Boundaries
Insulated Boundaries
4 1
And use the formula: u1,2 u2,2 u3,2
3 3
1 1.0010 1.0179 NaN NaN NaN NaN NaN NaN
1 1.0070 1.0404 0 0 0 0 0 0
1 1.0250 1.1077 0 0 0 0 0 0
1 1.0858 1.2735 0 0 0 0 0 0
1 1.2929 1.6133 0 0 0 0 0 0
1 2 2 2 2 2 2 2 2
Insulated Boundaries
69
The Crank-Nicolson Method
Step 3: Solving
70
The Crank-Nicolson Method
Examples
71
The Crank-Nicolson Method
Examples
72
The Crank-Nicolson Method
Examples
73
The Crank-Nicolson Method
Summary
74
The Crank-Nicolson Method
References
75