Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

Practical Methods for Partial

Dierential Equations
Practical 3
Rebecca Rollins
15913074
Queens University of Belfast
May 9, 2011
1
CONTENTS CONTENTS
Contents
1 The Problem 3
1.1 The Heat Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 The Wave Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Method of Separation of variables 4
2.1 The Heat Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 The Wave Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3 The Finite Dierence Method 18
3.1 Finite Dierence Method with the Heat Equation . . . . . . . . . . . . . . . . . 21
3.1.1 Crank-Nicolson Method - Stability . . . . . . . . . . . . . . . . . . . . . 22
3.2 Finite Dierence Method with the Wave Equation . . . . . . . . . . . . . . . . . 24
3.2.1 Stability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4 Comparison of Methods 28
4.1 The Heat Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.2 The Wave Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
A Appendix 35
B Appendix 36
2
CONTENTS 1. The Problem
1 The Problem
The aim of this report is to solve the following heat equation and wave equation, rstly, by
the method of separation of variables and then by applying the nite dierence method. The
results of these methods, for both equations, will be compared to show that they both give
the same solution. The MATLAB programs used to solve the heat and wave equations by the
method of separation of variables will be available in Appendix A, while the programs used to
solve the heat and wave equations are available in Appendix B.
1.1 The Heat Equation
The following heat equation will be solved;
u
t
= 2u
xx
, (1)
for 0 < x < 2, t > 0,
with the following boundary conditions;
u(0, t) = u(2, t) = 0, (2)
and initial condition;
u(x, 0) = exp(x)sin
4
(3x). (3)
1.2 The Wave Equation
The following wave equation will be solved;
u
tt
= 4u
xx
(4)
for 0 < x < 2, t > 0,
with the following boundary condition;
u(0, t) = 0 (5)
3
CONTENTS 2. Method of Separation of variables
and initial conditions;
u(x, 0) = exp[100(x )
2
] (6)
u
t
(x, 0) = 0. (7)
2 Method of Separation of variables
In the method of separation of variables, solutions of the following form will be looked for;
u(x
1
, x
2
, ..., x
n
) = X
1
(x
1
), X
2
(x
2
), ..., X
n
(x
n
)
where x
i
is a function of only of a single independent variable x
i
.
The separation will involve the introduction of (n 1) independent constants, k
1
, k
2
, ..., k
n
.
These are known as separation constants.
2.1 The Heat Equation
Consider the heat equation given by equation (8)
u
t
= 2u
xx
, (8)
for 0 < x < 2, t > 0.
In the method of separation of variables we seek the solution in the form of;
u(x, t) = X(x)T(t) (9)
Therefore;
u
t
= X(x)T

(t) (10)

2
u
x
2
= X

(x)T(t) (11)
Substitute equations 10 and 11 into equation (8);
X(x)T

(t) = 2X

(x)T(t) (12)
4
CONTENTS 2.1 The Heat Equation
Dividing equation 12 by 2X(x)T(t);
1
2
T

(t)
T(t)
=
X

(x)
X(x)
(13)
This is only possible if both terms equal a constant;
1
2
T

(t)
T(t)
=
X

(x)
X(x)
= (14)
where is an arbitrary constant, the separation constant.
Since x and t are independent variables;
X

= X (15)
T

= 2T (16)
Taking equation (16) to start;
T

= 2T
dT
dt
= 2T

dT
T
= 2

dt
ln T = 2t + C
T = e
2t
e
C
and replacing e
C
by C, where C is an arbitrary constant results in;
T(t) = Ce
2t
(17)
Now consider equation (15);
X

= X (18)
X

+ X = 0 (19)
5
CONTENTS 2.1 The Heat Equation
This equation has the general solution;
X(x) = Asin

+ Bcos

(20)
where A and B are arbitrary constants.
To satisfy the boundary conditions (2) for u(x, t) in the form of (9) requires
X(0) = 0 and X(2) = 0 (21)
Applied to X(x) from equation (23), the rst of these gives A = 0, while the second reads,
Bsin

= 0
To have a nonzero solution X(x), the sine function above must be zero, which gives;
2

= n, n = 1, 2, ...

=
n
2
the separation constant is given by;
=
n
2
4
(22)
(For < 0, the general solution is X(x) = Ae

x
+ Be

x
and the boundary conditions (2)
cannot be satised for non-zero A or B.)
and the corresponding solutions
X(x) = Bsin

nx
2

(23)
Combining equations (17) and (23), and using (22) yields the following result;
u(x, t) = B
n
sin

nx
2

exp

n
2
t
2

(24)
where B
n
is a new arbitrary constant, and n = 1, 2, ...
6
CONTENTS 2.1 The Heat Equation
A more general solution of equation (8) can be obtained by using the superposition princi-
ple i.e. equation (8) with boundary conditions (2) can be expressed as a linear combination
(superposition) of solutions (24) with dierent n;
u(x, t) =

n=1
B
n
sin

nx
2

exp

n
2
t
2

(25)
The coecients B
n
can be determined from the initial condition (3)
u(x, 0) = f(x) (26)
where f(x) = exp(x)sin
4
(3x)
This gives

n=1
B
n
sin

nx
2

= f(x) = exp(x) sin


4
(3x) (27)
To nd B
n
, multiply equation (27) by sin

mx
2

and integrate each term from 0 to 2.

2
0
sin

nx
2

sin

mx
2

dx =

2
0
sin

nx
2

sin

mx
2

dx (28)
=

2
0
cos

n m
2

x cos

n + m
2

dx (29)
=
2
2

nm
(30)
=
nm
, n, m = 1, 2, ... (31)
where
nm
= 1 for n = m and 0 for n = m, is the Kronecker delta. As a result, only the term
with n = m will give a non-zero contribution on the left-hand side, yielding;
B
n
=
1

2
0
sin

nx
2

f(x)dx (32)
=
1

2
0
sin

nx
2

exp(x) sin
4
(3x) (33)
Thus, the solution of equation (8) satisfying the boundary conditions (2) and intital condi-
tion (3) is;
u(x, t) =

n=1
B
n
sin

nx
2

exp

n
2
t
2

(34)
7
CONTENTS 2.1 The Heat Equation
where B
n
is given by equation (33).
Figure (1) shows the graph of the solution of the heat equation by the method of separation of
variables, while gure (2) shows the same solution but in 3D.
8
CONTENTS 2.1 The Heat Equation
F
i
g
u
r
e
1
:
T
h
e
s
o
l
u
t
i
o
n
o
f
t
h
e
h
e
a
t
e
q
u
a
t
i
o
n
b
y
t
h
e
m
e
t
h
o
d
o
f
s
e
p
a
r
a
t
i
o
n
o
f
v
a
r
i
a
b
l
e
s
.
T
h
e
p
a
r
a
m
e
t
e
r
s
u
s
e
d
t
o
g
i
v
e
t
h
i
s
s
o
l
u
t
i
o
n
a
r
e
d
e
l
t
a
t
=
0
.
0
0
5
,
i
x
m
a
x
=
2
5
a
n
d
i
t
m
a
x
=
3
0
0
.
9
CONTENTS 2.1 The Heat Equation
F
i
g
u
r
e
2
:
A
3
D
p
l
o
t
o
f
t
h
e
s
o
l
u
t
i
o
n
o
f
t
h
e
h
e
a
t
e
q
u
a
t
i
o
n
b
y
t
h
e
m
e
t
h
o
d
o
f
s
e
p
a
r
a
t
i
o
n
o
f
v
a
r
i
a
b
l
e
s
.
T
h
e
p
a
r
a
m
e
t
e
r
s
u
s
e
d
t
o
g
i
v
e
t
h
i
s
s
o
l
u
t
i
o
n
a
r
e
d
e
l
t
a
t
=
0
.
0
0
5
,
i
x
m
a
x
=
2
5
a
n
d
i
t
m
a
x
=
3
0
0
.
10
CONTENTS 2.2 The Wave Equation
2.2 The Wave Equation
Consider the wave equation (4)
u
tt
= 4u
xx
(35)
for 0 < x < 2, t > 0.
In the method of separation of variables we seek the solution in the form of;
u(x, t) = X(x)T(t) (36)
Therefore;
X(x)T

(t) = X

(x)T(t) (37)
Equation (37) can be rearranged to give
T

(t)
4T(t)
=
X

(x)
X(x)
(38)
This is only possible if both terms equal a constant;
T

(t)
4T(t)
=
X

(x)
X(x)
= (39)
where is an arbitrary constant, the separation constant.
T

= 4T (40)
X

= X (41)
since X and T are independent variables.
To satisfy equation 2 requires;
X(0) = 0 (42)
X(2) = 0 (43)
42 and 43 dene an eigenvalue problem where the eigenvalue is .
11
CONTENTS 2.2 The Wave Equation
Assume is real;
(a) Are there any positive eigenvalues?
Let =
2
, > 0
(41) X

+
2
X = 0, which is the equation for Simple Harmonic Motion and has the
general solution
X = Asin(x) + Bcos(x) (44)
where A and B are arbitrary constants.
Equation (42) B = 0, while equation (43) gives the following
sin(2) = 0 (45)
=
n
2
(46)
=
n
2
(47)
The corresponding eigenfunctions are
X
n
(x) = A
n
sin

nx
2

, n = 1, 2, ... (48)
(b) Can = 0 be an eigenfunction? From equation (41)
X

= 0 (49)
X

= A, where A is an arbitrary constant. (50)


X = Ax + B, where A and B are arbitrary constants. (51)
(42) B = 0 (52)
(43) A = 0 (53)
Thus, = 0 is an eigenvalue with eigenfunction
X
0
= A
0
(54)
12
CONTENTS 2.2 The Wave Equation
(c) Are there any negative eigenvalues?
Let =
2
, > 0
Eq. (41) X

=
2
X (55)
X = Asinh x + Bcosh x (56)
(42) B = 0 X = Asinh x
(43) is not possible for > 0.
Hence there are no negative eigenvalues.
The allowed eigenfunctions and eigenvalues are
X
0
(x) = A
0
,
0
= 0 (57)
X
n
(x) = A
n
sin

nx
2

,
n
=
n
2
4
, n 1. (58)
From equation (40) the corresponding forms for T are
X
0
T

0
T
0
= C
0
t + D
0
, (59)
X
n
T

n
= n
2
T
n
(60)
T
n
= C
n
sin(nt) + D
n
cos(nt), n = 1, 2, ... (61)
where C
0
, D
0
, C
n
and D
n
are arbitrary constants.
The most general separable form solution of (35) satisfying (5) is
u(x, t) = A
0
(C
0
t + D
0
) +

n=1
(C
n
sin(nt) + D
n
cos(nt)) A
n
sin

nx
2

(62)
u(x, t) = A
o
t + B
0
+ (A
n
sin(nt) + B
n
cos(nt)) sin

nx
2

(63)
where An, B
n
are arbitrary constants.
To satisfy (6) the following is required
u(x, 0) = B
0
+

n=1
B
n
sin

nx
2

= f(x) (64)
13
CONTENTS 2.2 The Wave Equation
where in this case f(x) = exp(100(x )
2
).
B
n
is found by multiplying both sides of equation (64) by sin

mx
2

and integrating each term


from 0 to 2 using the same method as in the heat equation.

2
0
sin

nx
2

sin

mx
2

dx =

2
0
sin

nx
2

sin

mx
2

dx (65)
=

2
0
cos

n m
2

x cos

n + m
2

dx (66)
=
2
2

nm
(67)
=
nm
, n, m = 1, 2, ... (68)
where
nm
= 1 for n = m and 0 for n = m, is the Kronecker delta. As a result, only the term
with n = m will give a non-zero contribution on the left-hand side, yielding;
B
n
=
1

2
0
sin

nx
2

f(x)dx (69)
=
1

2
0
sin

nx
2

exp(100(x )
2
)dx (70)
B
0
=
1
2

2
0
f(x)dx (71)
=
1
2

2
0
exp(100(x )
2
dx) (72)
The following is required in order to satisfy (7)
u
t
(x, t) =

n=1
nsin

nx
2

(A
n
cos(nt) B
n
sin(nt)) (73)
u
t
(x, 0) = A
n
nsin

nx
2

= g(x) (74)
g(x) = A
n
nsin

nx
2

(75)
14
CONTENTS 2.2 The Wave Equation
A
n
is found using the same procedure used to nd B
n
, hence,

2
0
g(x) sin

mx
2

dx = nA
n
(76)
A
n
=
1
n

2
0
g(x) sin
mx
2
dx (77)
However, in this case g(x) = 0
A
n
= 0, A
0
= 0. (78)
Hence the nal wave equation which satises the boundary and initial conditions is
u(x, t) = B
0
+

n=1
sin

nx
2

(B
n
cos(nt)) (79)
Figure (3) shows the graph of the solution of the wave equation by the method of separa-
tion of variables, while gure (4) shows the 3D solution.
15
CONTENTS 2.2 The Wave Equation
F
i
g
u
r
e
3
:
T
h
e
s
o
l
u
t
i
o
n
o
f
t
h
e
w
a
v
e
e
q
u
a
t
i
o
n
b
y
t
h
e
m
e
t
h
o
d
o
f
s
e
p
a
r
a
t
i
o
n
o
f
v
a
r
i
a
b
l
e
s
.
T
h
e
p
a
r
a
m
e
t
e
r
s
u
s
e
d
t
o
g
i
v
e
t
h
i
s
s
o
l
u
t
i
o
n
a
r
e
d
e
l
t
a
t
=
0
.
0
0
5
,
i
x
m
a
x
=
1
5
0
a
n
d
i
t
m
a
x
=
3
0
0
.
16
CONTENTS 2.2 The Wave Equation
F
i
g
u
r
e
4
:
A
3
D
p
l
o
t
o
f
t
h
e
s
o
l
u
t
i
o
n
o
f
t
h
e
w
a
v
e
e
q
u
a
t
i
o
n
b
y
t
h
e
m
e
t
h
o
d
o
f
s
e
p
a
r
a
t
i
o
n
o
f
v
a
r
i
a
b
l
e
s
.
T
h
e
p
a
r
a
m
e
t
e
r
s
u
s
e
d
t
o
g
i
v
e
t
h
i
s
s
o
l
u
t
i
o
n
a
r
e
d
e
l
t
a
t
=
0
.
0
0
5
,
i
x
m
a
x
=
1
5
0
a
n
d
i
t
m
a
x
=
3
0
0
17
CONTENTS 3. The Finite Dierence Method
3 The Finite Dierence Method
The nite dierence method can be used for most problems, including equations in general
domains and even non-linear equations.
Consider u(x, y) dened on the rectangular domain D
0 x , 0 y b (80)
Dene and equally spaced discrete grid or mesh of points in D;
x
i
= ix, i = 0 to (N 1) (81)
y
j
= jy, j = 0 to (N 1) (82)
Clearly
x =
a
(N 1)
(83)
y =
b
(N 1)
(84)
Let
u
ij
= u(x
i
, y
j
) (85)
Use the Taylor expansion of u about (x
i
, y
j
) to compute u(x
i+1
, y
j
);
u(x
i+1
, y
j
) = u(x
i
, y
j
)+
u
x
(x
i
, y
j
)x+
1
2

2
u
x
2
(x
i
, y
j
)(x)
2
+
1
6

3
u
x
3
(x
i
, y
j
)(x)
3
+
1
24

4
u
x
4
(x
i
, y
j
)(x)
4
+...
(86)
If then follows that
u
x
(x
i
, y
j
) =
u(x
i+1
, y
j
u(x
i
, y
j
)
x
+ O(x) (87)
=
u
i+1,j
u
i,j
x
+ O(x) (88)
18
CONTENTS 3. The Finite Dierence Method
The forward dierence approximation to u/x is
u
x
(x
i
, y
j
) =
u
i+1,j
u
i,j
x
(89)
Similarly by expanding u(x
i1
, y
j
) about (x
i
, y
j
) gives
u(x
i1
, y
j
) = u(x
i
, y
j
)
u
x
(x
i
, y
j
)x+
1
2

2
u
x
2
(x
i
, y
j
)(x)
2

1
6

3
u
x
3
(x
i
, y
j
)(x)
3
+
1
24

4
u
x
4
(x
i
, y
j
)(x)
4
...
(90)
This gives the backward dierence approximation
u
x
(x
i
, y
j
) =
u
i+1,j
u
i1,j
2
(91)
The central dierence approximation is obtained by subtracting (88) and (93)
u
x
(x
i
, y
j
) =
u
i+1,j
u
i1,j
2x
(92)
Similarly, approximations to
u
x
(x
i
, y
j
) can be obtained by adding equations (86) and (90)
u(x
i+1
, y
j
) + u(x
i1
, y
j
) = 2u(x
i
, y
j
) +

2
u
x
2
(x
i
, y
j
)(x)
2
+
1
12

4
u
x
4
(x
i
, y
j
)(x)
4
(93)
Thus

2
u
x
2
(x
i
, y
j
) =
u(x
i+1
, y
j
) 2u(x
i
, y
j
) + u(x
i1
, y
j
)
(x)
2
+ O((x)
2
) (94)
This gives the central dierence approximation to

2
u
x
2
, i.e.

2
u
x
2
(x
i
, y
j
) =
u
i+1,j
2u
i,j
+ u
i1,j
(x)
2
(95)
Similarly the central dierence approximation to

2
u
y
2
is

2
u
y
2
(x
i
, y
j
) =
u
i,j+1
2u
i,j
+ u
i,j1
(y)
2
(96)
19
CONTENTS 3. The Finite Dierence Method
It can be shown that the central dierence approximation to

2
u
xy

2
u
xy
(x
i
, y
j
) =
u
i+1,j+1
u
i+1,j1
u
i1,j+1
+ u
i1,j1
4xy
(97)
The error introduced by these approximations, see for example equation (88) and (94), is called
the truncation error.
20
CONTENTS 3.1 Finite Dierence Method with the Heat Equation
3.1 Finite Dierence Method with the Heat Equation
Consider the heat equation given by equation (8) for u(x, t)
u
t
= ku
xx
, 0 < x < 2, t > 0 (98)
where k is 2, and subject to
u(0, t) = u(2, t) = 0, (99)
u(x, 0) = f(x) = exp(x)sin
4
(3x) (100)
and f(0) = f(2) = 0 (101)
Use the following grid
x
i
= ix, x =
2
(N 1)
, i = 0, 1, ..., (N 1) (102)
t
n
= nt, chooset, n = 0, 1, 2, ... (103)
and dene
u
i,n
u(x
i
, t
n
) (104)
From the boundary conditions (99) and (100) the following is required
u
0,n
= u
N1,n
= 0, n 0 (105)
u
i,0
= f(x
i
) = f
i
, i = 0, 1, ..., (N 1) (106)
Using (89) and (95), (98) is approximated by
u
i,n+1
u
i,n
t
=
2(u
i+1,n
2u
i,n
+ u
i1,n
)
(x)
2
, (107)
1 i N 2, n 0 (108)
u
i,n+1
= u
i,n
+(u
i+1,n
2u
i,n
+ u
i1,n
), (109)
1 i N 2, n 0. (110)
where = 2t/(x)
2
21
CONTENTS 3.1 Finite Dierence Method with the Heat Equation
3.1.1 Crank-Nicolson Method - Stability
An ecient and stable method for solving the heat equation given by dened by equations (98), (99)
and (100) is the Crank-Nicolson method. This is shown as follows;
Use the forward dierence approximation (89) for u/x and (94) for
2
u/x
2
, but averaged
over the times n and n + 1, to get
u
i,n+1
u
i,n
t
= k

u
i+1,n
2u
i,n
+ u
i1,n
2(x)
x
+
u
i+1,n+1
2u
i,n+1
+ u
i1,n+1
2(x)
2

(111)
where k = 2 in the case of equation (8).
It can be seen that an anlytical solution of equations (98), (99) and (100) is
u(x, t) = exp(kL
2
t) sin(Lx) (112)
Given (112) a solution of the following form is required
u
i,n
= A(n) = sin(L
i
x) (113)
To examine stability use (113) to get
A(n + 1) = [1 + 4sin
2
(Lx/2)] (114)
= [1 4sin
2
(Lx/2)]A(n) (115)
Then setting
A(n) = A(0)r
n
(116)
with r =
1 4sin
2
(Lx/2)
1 + 4sin
2
(Lx/2)
(117)
For an arbitrary integer L, | r | 1 and so (111) does not blow up with increasing n and is
stable for all , i.e., all x and t.
The Crank-Nicolson method is implicit. In other words, it involves solving a system of lin-
ear equations to obtain u at the later time from u at the previous time.
Figure (5) shows the solution of the heat equation using the nite dierence method, with the
Crank-Nicolson method to ensure stability.
22
CONTENTS 3.1 Finite Dierence Method with the Heat Equation
F
i
g
u
r
e
5
:
T
h
e
s
o
l
u
t
i
o
n
o
f
t
h
e
h
e
a
t
e
q
u
a
t
i
o
n
b
y
t
h
e

n
i
t
e
d
i

e
r
e
n
c
e
m
e
t
h
o
d
u
s
i
n
g
C
r
a
n
k
-
N
i
c
o
l
s
o
n
s
c
h
e
m
e
.
T
h
e
p
a
r
a
m
e
t
e
r
s
u
s
e
d
t
o
g
i
v
e
t
h
i
s
s
o
l
u
t
i
o
n
a
r
e
d
e
l
t
a
t
=
0
.
0
0
5
,
i
x
m
a
x
=
2
5
a
n
d
i
t
m
a
x
=
3
0
0
.
23
CONTENTS 3.2 Finite Dierence Method with the Wave Equation
3.2 Finite Dierence Method with the Wave Equation
Consider the wave equation given by equation (4) for u(x, t)
u
tt
= C
2
u
xx
, 0 < x < 2, t > 0 (118)
where C is 2 in this case, and subject to
u(0, t) = u(2, t) = 0, (119)
u(x, 0) = f(x) = exp[100(x )
2
] (120)
u
t
(x, 0) = g(x) = 0 (121)
Use the following grid
x
i
= ix, x =
2
(N 1)
, i = 0, 1, ..., (N 1) (122)
t
n
= nt, chooset, n = 0, 1, 2, ... (123)
and dene
u
i,n
u(x
i
, t
n
) (124)
Using the central dierence approximations results in
u
i,n+1
2
i,n
+ u
i,n1
(t)
2
=
C
2
(u
i+1,n
2u
i,n
+ u
i1,n
(x)
2
(125)
a i N 2, n 0 (126)
The boundary values (119) are
u
0,n
= u
N1,n
= 0 (127)
(126) can be rearranged to give
u
i,n+1
= 2(1 )u
i,n
u
i,n1
+ (u
i1,n
+ u
i+1,n
) (128)
24
CONTENTS 3.2 Finite Dierence Method with the Wave Equation
where
C
2
(t)
2
(x)
2
(129)
To start the iteration u
i,0
and u
i,1
are required. From (120)
u
i,0
= f(x
i
) (130)
To calculate u
i,1
, the central dierence approximation (92) is used in equation (121):
u
i,1
u
i,1
= 2tg(x
i
) (131)
(132)
However, from equation (121) g(x) = 0 so equation (131) becomes
u
i,1
u
i,1
= 0 u
i,1
= u
i,1
(133)
3.2.1 Stability
To analyse stability a solution of (129) are required in the following form
u
i,n
= A(n) sin(L
i
x) (134)
where L is a positive integer.
Inserting (134) into (129)
A(n + 1) = 2(1 )A(n) A(n 1) + 2cos(Lx)A(n) (135)
A(n) = Cr
n
(136)
Solves the above equation provided r
2
2r[1 2 sin
2
(Lx/2)] + 1 = 0
25
CONTENTS 3.2 Finite Dierence Method with the Wave Equation
The roots of this equation are
r
1
r
2

= [1 2 sin
2
(Lx/2)]

[1 2 sin
2
(Lx/2)]
2
1 (137)
and the solution of (134) is
A(n) = C
1
r
n
1
+ C
2
r
n
2
(138)
If [1 2 sin
2
(Lx/2)]
2
> 1 then the magnitude of one of the roots is > 1 and so (138) increase
indenitely in magnitude with increasing n, i.e. there is instability.
If [1 2 sin
2
(Lx/2)]
2
< 1 then r
1
and r
2
are complex conjugates, see (137). From (137)
the square of the magnitude of the roots is 2[1 2 sin
2
(Lx/2)]
2
1.
Thus (138) will not grow in magnitude indenitely with n if:
2[1 2 sin
2
(Lx/2)]
2
1 < 1 (139)
1 2 sin
2
(Lx/2)]
2
< 1 (140)
Thus (135) will be stable for all L if:
[1 2]
2
< 1 < 1
x
t
0
> C (141)
This is called the Courant, Friedricks, Lewy (CFL) condition.
Figure (6) shows the solution of the wave equation using the nite dierence method, with the
CFL condition satised by 4.19 > C, where C = 2.
26
CONTENTS 3.2 Finite Dierence Method with the Wave Equation
F
i
g
u
r
e
6
:
T
h
e
g
r
a
p
h
o
f
t
h
e
s
o
l
u
t
i
o
n
o
f
t
h
e
w
a
v
e
e
q
u
a
t
i
o
n
u
s
i
n
g
t
h
e

n
i
t
e
d
i

e
r
e
n
c
e
m
e
t
h
o
d
.
T
h
e
p
a
r
a
m
e
t
e
r
s
u
s
e
d
t
o
g
i
v
e
t
h
i
s
s
o
l
u
t
i
o
n
a
r
e
d
e
l
t
a
t
=
0
.
0
0
5
,
i
x
m
a
x
=
1
5
0
a
n
d
i
t
m
a
x
=
3
0
0
.
27
CONTENTS 4. Comparison of Methods
4 Comparison of Methods
4.1 The Heat Equation
The graph of the solution by the method of separation of variables, shown in gure (1), is
overlaid on the graph of the solution by the nite dierence method using the Crank-Nicolson
scheme, shown in gure (5). Figure (7) shows that both methods produce the same solution.
It can be seen from both gure (7) and (2) that the heat is greatest and apparent at a few
points initially but as time increases the heat quickly dissipates.
The parameters used to produce this solution and the subsequent graph are;
1. deltat= 0.005
2. itmax=25
3. ixmax=300
28
CONTENTS 4.1 The Heat Equation
F
i
g
u
r
e
7
:
T
h
e
g
r
a
p
h
o
f
t
h
e
s
o
l
u
t
i
o
n
o
f
t
h
e
h
e
a
t
e
q
u
a
t
i
o
n
b
y
t
h
e
m
e
t
h
o
d
o
f
s
e
p
a
r
a
t
i
o
n
o
f
v
a
r
i
a
b
l
e
s
o
v
e
r
l
a
i
d
w
i
t
h
t
h
e
s
o
l
u
t
i
o
n
b
y
t
h
e

n
i
t
e
d
i

e
r
e
n
c
e
m
e
t
h
o
d
,
u
s
i
n
g
t
h
e
C
r
a
n
k
-
N
i
c
o
l
s
o
n
s
c
h
e
m
e
.
29
CONTENTS 4.2 The Wave Equation
4.2 The Wave Equation
The graph of the solution by the method of separation of variables, shown in gure (3), is over-
laid on the graph of the solution by the nite dierence method shown in gure (6). Figure (8)
shows that both methods produce the same solution. In the case of the nite dierence method
stability is ensured as the CFL condition is satised, by 4.19 > C, where C = 2.
The parameters used to produce this solution and the subsequent graph are;
1. deltat= 0.005
2. itmax=150
3. ixmax=300
Figure (8) shows the wave at the boundary conditions which splits giving a wave form trav-
elling in the positive x direction and another wave form travelling in the negative x direction.
Adjusting the parameters, gure (10) gives a clearer indication that given the initial condi-
tion of u
t
(x, 0) = g(x) = 0, this solution satises dAlemberts formula which is given as
u(x, t) = F(x ct) + G(x + ct) (142)
=
1
2
[f(x ct) + f(x + ct)] +
1
2c

x+ct
xct
g()d (143)
By increasing the increasing the time considered, which means adjusting the parameter
itmax, shows the eventually the both wave forms will come into contact with something which
will cause the wave forms to bounce back. This is illustrated in gure (??), and can easily be
seen in the 3D plot of the solution of wave equation by the method of separation of variables
given by gure (11)
30
CONTENTS 4.2 The Wave Equation
F
i
g
u
r
e
8
:
T
h
e
g
r
a
p
h
o
f
t
h
e
s
o
l
u
t
i
o
n
o
f
t
h
e
h
e
a
t
e
q
u
a
t
i
o
n
b
y
t
h
e
m
e
t
h
o
d
o
f
s
e
p
a
r
a
t
i
o
n
o
f
v
a
r
i
a
b
l
e
s
o
v
e
r
l
a
i
d
w
i
t
h
t
h
e
s
o
l
u
t
i
o
n
b
y
t
h
e

n
i
t
e
d
i

e
r
e
n
c
e
m
e
t
h
o
d
.
31
CONTENTS 4.2 The Wave Equation
F
i
g
u
r
e
9
:
T
h
e
s
o
l
u
t
i
o
n
o
f
t
h
e
w
a
v
e
e
q
u
a
t
i
o
n
b
y
t
h
e
m
e
t
h
o
d
o
f
s
e
p
a
r
a
t
i
o
n
o
f
v
a
r
i
a
b
l
e
s
i
l
l
u
s
t
r
a
t
i
n
g
d

A
l
e
m
b
e
r
t

s
f
o
r
m
u
l
a
.
T
h
e
f
o
l
l
o
w
i
n
g
v
a
l
u
e
s
w
e
r
e
u
s
e
d
t
o
p
r
o
d
u
c
e
t
h
e
g
r
a
p
h
d
e
l
t
a
t
=
0
.
1
,
i
t
m
a
x
=
1
0
,
i
x
m
a
x
=
3
0
0
.
32
CONTENTS 4.2 The Wave Equation
F
i
g
u
r
e
1
0
:
T
h
e
s
o
l
u
t
i
o
n
o
f
t
h
e
w
a
v
e
e
q
u
a
t
i
o
n
b
y
t
h
e
m
e
t
h
o
d
o
f
s
e
p
a
r
a
t
i
o
n
o
f
v
a
r
i
a
b
l
e
s
,
w
h
i
c
h
i
l
l
u
s
t
r
a
t
e
s
t
h
a
t
t
h
e
w
a
v
e
f
o
r
m
s

h
i
t

s
o
m
e
t
h
i
n
g
w
h
i
c
h
c
a
u
s
e
s
t
h
e
w
a
v
e
f
o
r
m
s
t
o
b
o
u
n
c
e
b
a
c
k
.
T
h
e
f
o
l
l
o
w
i
n
g
v
a
l
u
e
s
w
e
r
e
u
s
e
d
t
o
p
r
o
d
u
c
e
t
h
e
g
r
a
p
h
d
e
l
t
a
t
=
0
.
0
0
5
,
i
t
m
a
x
=
2
0
0
,
i
x
m
a
x
=
5
0
0
.
33
CONTENTS 4.2 The Wave Equation
F
i
g
u
r
e
1
1
:
A
3
D
p
l
o
t
o
f
t
h
e
s
o
l
u
t
i
o
n
o
f
t
h
e
w
a
v
e
e
q
u
a
t
i
o
n
b
y
t
h
e
m
e
t
h
o
d
o
f
s
e
p
a
r
a
t
i
o
n
o
f
v
a
r
i
a
b
l
e
s
s
h
o
w
i
n
g
t
h
e
w
a
v
e
f
o
r
m
s
b
o
u
n
c
i
n
g
b
a
c
k
.
T
h
e
f
o
l
l
o
w
i
n
g
v
a
l
u
e
s
w
e
r
e
u
s
e
d
t
o
p
r
o
d
u
c
e
t
h
e
g
r
a
p
h
d
e
l
t
a
t
=
0
.
0
0
5
,
i
t
m
a
x
=
2
0
0
,
i
x
m
a
x
=
3
0
0
.
34
CONTENTS A. Appendix
A Appendix
35
CONTENTS B. Appendix
B Appendix
36

You might also like