CHEN30101 solutions to sheet 6 1. Suppose that we are using the

Engineering Mathematics | CHEN30101
solutions to sheet 6
1. Suppose that we are using the FTCS approximation method to solve the
heat equation. Denote the spatial grid resolution by h and suppose that
the grid points are x0 , x1 , . . . , x10 at time level tn = nk.
Determine the discrete equation that un9 , un10 and un11 will satisfy if the
condition at the right-hand boundary is given by (i) u = 1, (ii) ∂u
∂x = 0,
∂u
(iii) ∂u
=
2.3,
(iv)
+
4.7u
=
2.1.
∂x
∂x
We make use the centered difference approximation
un − un9
∂u
(x10 , tn ) ≈ 11
.
∂x
2h
u(x10 , tn ) ≈ un10 ,
The resulting discrete equations are:
(i) u(x10 , tn ) ≈ un10 = 1.
∂u
un − un9
(ii)
(x10 , tn ) ≈ 11
= 0, =⇒ un11 = un9 .
∂x
2h
∂u
un − un9
(iii)
(x10 , tn ) ≈ 11
= 2.3, =⇒ un11 = un9 + 4.6h.
∂x
2h
∂u
un − un9
(iv)
(x10 , tn ) + 4.7un (x10 , tn ) ≈ 11
+ 4.7un10 = 2.1,
∂x
2h
=⇒ un11 = un9 − 9.4hun10 + 4.2h.
2. Consider the initial value problem: find u(x, t) such that
ut − uxx = 0
in (0, 1) × (0, τ )
u(0, t) = 0;
u(1, t) = 0,
2
u(x, 0) = x (1 − x),
t>0
x ∈ (0, 1).
Using a grid resolution of h = 0.2 and k = 0.01, carry out two steps of
the FTCS approximation method.
What is the maximum time step possible if a stable FTCS approximation
is to be computed for a spatial grid resolution of (i) h = 10, (ii) h = 1,
(iii) h = 0.1, (iv) h = 0.01?
For each interior grid point x1 = 0.2, x2 = 0.4, x3 = 0.6 and x4 = 0.8, we
use a centered difference approximation in space at time level n, so that
u(xj , tn ) ≈ unj ,
uxx (xj , tn ) ≈
unj−1 − 2unj + unj+1
,
h2
in combination with a forward difference approximation in time, so that
ut (xj , tn ) ≈
− unj
un+1
j
k
1
=
unj−1 − 2unj + unj+1
.
h2
which gives us an explicit formula for computing un+1
. The values of un0
j
and un5 are zero from the boundary conditions. The results are tabulated
below.
From Definition 40 in the notes we have that kmax = 12 h2 . Time steps for
the four distinct values of h are tabulated below.
h
kmax
10
50
1
0.5
0.1
0.005
0.01
0.00005
3. Consider the initial value problem: find u(x, t) such that
ut − uxx = 0
in (0, 1) × (0, τ )
u(0, t) = 0;
u(1, t) = 1,
2
t>0
x ∈ (0, 1).
u(x, 0) = x ,
Using a grid resolution of h = 0.25 and k = 0.1, carry out two steps of
the Crank–Nicolson approximation method by working out the discrete
equations one at a time, and then solving a 3 × 3 equation system at each
time step. Work to an accuracy of four decimal places.
For the first step of the Crank–Nicolson method, we need to form an
equation based around each of points A, B and C shown below.
2
For each of these points we take the average of the centered difference
approximation in space at time levels n − 1 and n, so that
"
#
n−1
n−1
n−1
1 unj−1 − 2unj + unj+1 uj−1 − 2uj + uj+1
uxx (xj , tn ) ≈
+
,
2
h2
h2
in combination with a backward difference approximation in time, so that
"
#
n−1
n−1
n−1
unj − un−1
1 unj−1 − 2unj + unj+1 uj−1 − 2uj + uj+1
j
ut (xj , tn ) ≈
=
+
.
k
2
h2
h2
which gives us an implicit formula for computing unj . Note that the values
of un0 and un4 are equal to zero, and the values of u0n−1 and un−1
are equal
4
to one (from the boundary conditions).
At the point A, we have
1 B −2A+0 0.25−2 × 0.0625
uxx ≈
+
= −16A + 8B + 1
2
0.252
0.252
A − 0.0625
= 10A − 0.625.
ut ≈
0.1
So that −16A + 8B + 1 = 10A − 0.625 =⇒ −26A + 8B = −1.625.
(A)
At the point B, we have
1 C −2B +A 0.5625−2 × 0.25+0.0625
uxx ≈
+
= 8A − 16B + 8C + 1
2
0.252
0.252
B − 0.25
= 10B − 2.5.
ut ≈
0.1
So that 8A−16B +8C +1 = 10B −2.5 =⇒ 8A−26B +8C = −3.5.
(B)
At the point C, we have
1 1−2C +B 1−2 × 0.5625+0.25
uxx ≈
+
= 8B − 16C + 9
2
0.252
0.252
C − 0.5625
ut ≈
= 10C − 5.625.
0.1
So that 8B − 16C + 9 = 10C − 5.625 =⇒ 8B − 26C = −14.625.
(C)
Solving the three equations (A), (B), (C) gives the solution values at the
first time level: A = 0.1866, B = 0.4033, C = 0.6866.
For the second step of the Crank–Nicolson method, we need to form an
equation based around each of points D, E and F in the figure. Starting
at the point D,
1 E − 2D + 0 B − 2A + 0
D−A
+
=
2
2
2
(0.25)
(0.25)
0.1
So that −26D + 8E = 6A − 8B = −2.1068
3
(D)
At the point E,
1 F − 2E + D C − 2B + A
E−B
+
=
2
2
2
(0.25)
(0.25)
0.1
So that 8D − 26E + 8F = −8A + 6B − 8C = −4.5658. (E)
Finally, at the point F ,
1 1 − 2F + E 1 − 2C + B
F −C
+
=
2
2
2
(0.25)
(0.25)
0.1
So that 8E − 26F = −8B + 6C − 16 = −4.5658. (F )
Solving the three equations (D), (E), (F ) gives the solution values at the
second time level: D = 0.2251, E = 0.4679, F = 0.7251.
4. Consider the initial value problem: find u(x, t) such that
ut − uxx = 0
in (0, 1) × (0, τ )
u(0, t) = 0;
u(1, t) = 0,
u(x, 0) = sin(πx),
t>0
x ∈ (0, 1).
Using a grid resolution of h = 0.2 and k = 0.01, carry out the first step of
(a) the FTCS approximation method
(b) the BTCS approximation method
(c) the Crank–Nicolson method.
Work to an accuracy of four decimal places and compare your numerical
2
results with the exact values that are given by u(x, t) = e−π t sin(πx).
For the first step of the BTCS method, we need to form an equation based
around each grid point at the first time level. For each of these points we
take a centered difference approximation in space at time levels n so that
unj−1 − 2unj + unj+1
uxx (xj , tn ) ≈
h2
in combination with a backward difference approximation in time, so that
unj − ujn−1
unj−1 − 2unj + unj+1
.
k
h2
which gives us an implicit formula for computing unj . Note that the values
of un0 and un5 are equal to zero from the boundary conditions.
ut (xj , tn ) ≈
=
Results for the three different finite difference approximations and the
exact values at the grid points are tabulated below. Surprisingly, the
FTCS results are the most accurate!
xj
(f tcs)
(btcs)
(cn)
u(xj , 0.01)
0
0
0
0
0
0.2
0.5317
0.5365
0.5342
0.5325
0.4
0.8622
0.8682
0.8644
0.8617
4
0.6
0.8622
0.8682
0.8644
0.8617
0.8
0.5317
0.5365
0.5342
0.5325
1
0
0
0
0
5. Consider the initial value problem: find u(x, t) such that
utt − uxx = 0
u(0, t) = 0;
in (0, 1) × (0, τ )
u(1, t) = 0,
u(x, 0) = sin(πx),
t>0
ut (x, 0) = 0,
x ∈ (0, 1).
(a) By defining a new dependent variable v = ut , convert the problem
to a system of two linear PDEs that are first order in time.
(b) Hence, using a grid resolution of h = 0.25 and k = 0.01, carry out two
steps of the FTCS approximation method. Record all your answers
to an accuracy of four decimal places.
(a) Making the substitution the coupled system of PDEs is given by
ut − v = 0
in (0, 1) × (0, τ )
vt − uxx = 0
u(0, t) = 0; u(1, t) = 0,
u(x, 0) = sin(πx),
v(x, 0) = 0,
t>0
x ∈ (0, 1).
(b) For each interior grid point we use a centered difference approximation in space at time level n, so that
unj−1 − 2unj + unj+1
u(xj , tn ) ≈ unj , uxx (xj , tn ) ≈
,
h2
in combination with a forward difference approximation in time, so
that
un+1
− unj
j
ut (xj , tn ) ≈
= vjn
k
vjn+1 − vjn
unj−1 − 2unj + unj+1
vt (xj , tn ) ≈
=
,
k
h2
which gives us explicit formulas for computing un+1
and vjn+1 . The
j
n
n
values of u0 and u4 are zero from the boundary conditions. The
results are tabulated below.
5
6. Consider the boundary value problem: find u(x, y) such that
uxx + uyy = 0
in (0, 3) × (0, 3)
u(0, y) = 0,
u(3, y) = 0,
y ∈ (0, 3)
u(x, 0) = x(3 − x),
u(x, 3) = 0,
x ∈ (0, 3).
Consider the grid with h = 1. Compute an approximation to the solution
using the 5-point difference scheme by working out the discrete equations
one at a time, and then solving a 4 × 4 equation system by hand.
The grid points are illustrated below.
For each interior grid point we use a centered difference approximation in
each space direction so that u(xi , yj ) ≈ ui,j and
ui−1,j − 2ui,j + ui+1,j
,
h2
−ui−1,j + 2ui,j − ui+1,j
ui,j−1 − 2ui,j + ui,j+1
=
uyy (xi , yj ) ≈
2
h
h2
uxx (xi , yj ) ≈
which gives an implicit formulas for computing ui,j . Note that the factor
h2 cancels from both sides to give the formula (5pt) in the lecture notes.
The edge values u0,j , u3,j ui,0 and ui,3 are given by the specified boundary
conditions. Thus working out the equations in turn, we get a 4 × 4 system
4A − B − C = 2
(A)
−A + 4B − D = 2
(B)
−A + 4C − D = 0
(C)
−B − C + 4D = 0.
(D)
Solving these four equations gives the solution values at the grid points:
A = 3/4, B = 3/4, C = 1/4, D = 1/4.
6
The same problem can be set up and solved using laplacefd. This gives
the output below.
>> h=1; xx=0:h:3; yy=[3:-h:0]’;
>> [u,A] = laplacefd(xx,0*xx,xx.*(3-xx),yy,0*yy,0*yy);
subdivision parameter : 1
u =
0
0
0
0
0
0.2500
0.7500
2.0000
0
0.2500
0.7500
2.0000
0
0
0
0
7. Consider the boundary value problem: find u(x, y) such that
uxx + uyy = 0
in (0, 1) × (0, 1)
u(0, y) = y,
u(1, y) = 1 + 2y,
y ∈ (0, 1)
u(x, 0) = x,
u(x, 1) = 1 + 2x,
x ∈ (0, 1).
Consider the grid with h = 0.25. Construct an approximation to the
solution using the 5-point difference scheme by working out the discrete
equations one at a time, and forming a 9 × 9 equation system. (You do
not need to solve the system.)
Solving this problem using laplacefd gives the output below.
>> h=0.25; xx=0:h:1; yy=[1:-h:0]’;
>> [u,A] = laplacefd(xx,1+2*xx,xx,yy,yy,1+2*yy)
subdivision parameter : 0.25
u =
1.0000
0.7500
0.5000
0.2500
0
>> full(A)
ans =
4
-1
-1
4
0
-1
-1
0
0
-1
0
0
0
0
0
0
0
0
1.5000
1.1875
0.8750
0.5625
0.2500
0
-1
4
0
0
-1
0
0
0
2.0000
1.6250
1.2500
0.8750
0.5000
-1
0
0
4
-1
0
-1
0
0
0
-1
0
-1
4
-1
0
-1
0
7
2.5000
2.0625
1.6250
1.1875
0.7500
0
0
-1
0
-1
4
0
0
-1
0
0
0
-1
0
0
4
-1
0
3.0000
2.5000
2.0000
1.5000
1.0000
0
0
0
0
-1
0
-1
4
-1
0
0
0
0
0
-1
0
-1
4