You are on page 1of 2

FTCS for the 1D Heat Equation, in a Nutshell ME 448/548

Winter 2014

1. Combine finite difference approximations for u/t at x = xi

uk+1 uki

u i
= + O(t). (1)
t tk ,xi t

and 2 u/x2 at time tk

2 u uki1 2uki + uki+1



= + O(x2 ). (2)
x2 tk ,xi x2

To get
uk+1 uki uk 2uki + uki+1
i
= i1 + O(t) + O(x2 ) (3)
t x2
Drop the truncation error terms and solve for uk+1
i

uk+1
i = ruki+1 + (1 2r)uki + ruki1 (4)

where r = t/x2 . Equation (4) is the computational formula for the FTCS scheme. It is
an explicit scheme because it provides a simple formula to update uk+1
i independently of the
other nodal values at tk+1 .

2. Computational Molecule
FTCS scheme enables
explicit calculation of
t .. .. .. .. .. .. ..
. . . . . . . u at this node
k+1
k
k 1
Solution is known
for these nodes

t=0, k=1
i=1 i 1 i i+1 nx
x=0 x=L

3. Matlab implementation: code from demoFTCS


% --- Assign IC and BC. u is initialized to a vector that includes BC
x = linspace(0,L,nx); u = sin(pi*x/L);

% --- Loop over time steps


for k=2:nt
uold = u; % prepare for next step
for i=2:nx-1
u(i) = r*uold(i-1) + r2*uold(i) + r*uold(i+1);
end
end

A more general implementation is in heatFTCS.


2

4. Stability: A computational scheme is stable if


small perturbations in the values of the dependent Unstable
log(t) (x)2
variable do not grow unboundedly. The perturba- B t = 2
tions may arise in the initial conditions, boundary A
conditions, or from roundoff.
The FTCS is conditionally stable for the heat Stable
C
equation when
t log(x)
r= < 1/2
x2
5. Measuring truncation error: When an analytical solution is known, we can compare the nu-
merical solution (in this case from FTCS) with the exact solution.
Define:
1
E(nx , nt ) = kuki u(xi , tk )k2 (5)
nx
where nx is the number of x-direction nodes in the mesh.
The local error at x = xi and t = tk is

eki = uki u(xi , tk ). (6)

Let ek as an RMS average error per node at time step tk


"nx
#1/2
k 1 X
e (ek )2 (7)
nx i=1 i

This definition of the error is consistent with the order of accuracy of the solution. A little
algebra shows that E(nx , nt ) = ek .
We are most interested in the rate at which e or E(nx , nt ) approach zero. Applying FTCS to
the heat equation gives
E(nx , nt ) = O(t) + O(x2 )

The demoFTCS code exhibits the correct truncation error behavior. We conclude that demoFTCS
is a correct implementation of FTCS.
2
10
>> convFTCS FTCS
ideal

nx nt error E(j)/E(j-1) p
3
8 21 6.028e-03 NaN 0.0000 10
16 92 1.356e-03 0.2249 2.1524
32 386 3.262e-04 0.2406 2.0553
64 1589 7.972e-05 0.2444 2.0329
E(nx,ny)

4
128 6453 1.970e-05 0.2471 2.0170 10
256 26012 4.895e-06 0.2485 2.0085

5
10

6
10 3 2 1 0
10 10 10 10
x

You might also like