FTCS Solution To The Heat Equation: ME 448/548 Notes
FTCS Solution To The Heat Equation: ME 448/548 Notes
ME 448/548 Notes
Gerald Recktenwald
Portland State University
Department of Mechanical Engineering
gerry@pdx.edu
∂u uk+1
i − uki
≈
∂t ∆t
uk+1 − uki
∂u i
= + O(∆t) (1)
∂t tk ,xi ∆t
Approximate the spatial derivative with the central difference operator and take all nodal
values at time tk .
2
∂ u uki−1 − 2uki + uki+1 2
= + O(∆x ) (2)
∂x2 ∆x2
xi
Substitute Equation (1) and Equation (2) into the heat equation
k k k
uk+1
i − u k
i u i−1 − 2u i + u i+1 2
=α + O(∆t) + O(∆x ) (3)
∆t ∆x2
uk+1
i − uki uki−1 − 2uki + uki+1
=α (4)
∆t ∆x2
t=0, k=1
i=1 i 1 i i+1 nx
x=0 x=L
where u(k+1) is the vector of u values at time step k + 1, u(k) is the vector of u values
at time step k, and A is the tridiagonal matrix
1 0 0 0 0 0
r (1 − 2r) r 0 0 0
0 r (1 − 2r) r 0 0
A= ... ... ... . (7)
0 0 0
(1 − 2r)
0 0 0 r r
0 0 0 0 0 1
The first and last rows of A are set to enforce the Dirichlet boundary conditions at x = 0
and x = L.
0.14
FTCS
>> demoFTCS Exact
Error in FTCS solution = 0.002221 0.12
0.1
0.08
u
0.06
0.04
0.02
0
0 0.2 0.4 0.6 0.8 1
x
1 1 1
0 0 0
−1 −1 −1
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
2 2 2
Initial Condition Initial Condition Initial Condition
FTCS solution FTCS solution FTCS solution
1.5 t = 0.82 1.5 t = 1.88 1.5 t = 2.00
1 1 1
0 0 0
−1 −1 −1
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
2 2 2
Initial Condition Initial Condition Initial Condition
FTCS solution FTCS solution FTCS solution
1.5 t = 1.22 1.5 t = 1.92 1.5 t = 2.04
1 1 1
0 0 0
−1 −1 −1
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Observations:
• The FTCS solution appears to be stable at first
• Toward the end of the simulation time, oscillations grow exponentially
• Instability is not caused by truncation error
• Instability is fed by round-off errors, but not directly caused by round-off
The pattern is
(2)
ui = (1 − 4r)u0(xi)
(3) (2) 2
ui = (1 − 4r)ui (xi) = (1 − 4r) u0(xi)
(4) (3) 3
ui = (1 − 4r)ui (xi) = (1 − 4r) u0(xi)
(2)
where ui is the numerical solution at xi and k = 2;
and where (1 − 4r)2 is the square of (1 − 4r)
1
1 − 4r < 1 =⇒ −4r < 2 =⇒ r > − true for any r > 0.
2
The second case is
1
−(1 − 4r) < 1 =⇒ 4r < 2 =⇒ r <
2
The quick and dirty stability analysis shows that the FTCS scheme is stable only if
α∆t 1
r= < . (8)
∆x2 2
For a given ∆x, the stability limit for FTCS imposes an upper limit on ∆t
∆x2
∆t < (9)
2α
1
Choosing ∆t and ∆x so that r < does not guarantee an accurate numerical solution.
2
1
r< only guarantees that the FTCS solution will not blow up.
2
log(∆x)
1 k
E(nx, nt) = √ kui − u(xi, tk )k2 (10)
nx
√
The factor of 1/ nx converts kuki − u(xi, tk )k2 to an average error.
If the solution to the heat equation is smooth, then E(nx, nt) = O(∆t) + O(∆x2)
Suppose we don’t know the exponent of the truncation error for our code.
Lp
p
E(nx, nt) = O(∆x ) = O
(nx − 1)p
Therefore, we expect
1
E(nx, nt) = O
npx
With
1
E(nx, nt) = O
npx
we form the ratio
npx,1 nx,1 p
E(nx,2, nt)
= p =
E(nx,1, nt) nx,2 nx,2
Solve for p
log (E(nx,2, nt)/E(nx,1, nt))
p= .
log (nx,1/nx,2)
function convFTCS
% convFTCS Convergence of FTCS on a series of finer spatial meshes
% --- Loop over mesh sizes, store error and compute order of scheme
fprintf(’\n nx nt error E(j)/E(j-1) p\n’);
er = NaN; p = 0;
for j=1:length(nx);
e(j) = demoFTCS(nx(j),nt(j));
if j>1
er = e(j)/e(j-1); p = log(er)/log(nx(j-1)/nx(j));
end
fprintf(’ %5d %5d %11.3e %8.4f %8.4f\n’,nx(j),nt(j),e(j),er,p);
end
−2
10
FTCS
>> convFTCS ideal
nx nt error E(j)/E(j-1) p −3
10
8 21 6.028e-03 NaN 0.0000
16 92 1.356e-03 0.2249 2.1524
32 386 3.262e-04 0.2406 2.0553
E(nx,ny)
−4
64 1589 7.972e-05 0.2444 2.0329 10
128 6453 1.970e-05 0.2471 2.0170
256 26012 4.895e-06 0.2485 2.0085
−5
10
The last column of text output shows
that demoFTCS has the right truncation
error behavior. −6
10 −3 −2 −1 0
10 10 10 10
x
α∆t
r= < 1/2
∆x2
In two spatial dimensions with ∆y = ∆x, the stability condition is r < 1/4. In 3D
with ∆y = ∆z = ∆x, the stability condition is r < 1/8.
• There are much better schemes for solving the heat equation.
• FTCS is a toy used to introduce the numerical solution of PDEs