To find the matrix form of the FTCS scheme we first recall the
discretised form of the FTCS scheme:
 |
(3.13) |
If we stare at this equation for long enough we might be able to see
exactly why we can turn this into a matrix form. Let's pay attention
to just the right-hand side of
Equation (3.13). We can see that we have
three terms of the solution
at three points in space, but at
the same point in time. This suggests that we could write
as a vector with each element representing the function value
at each position in space and for the current point in time. Also, to
``pick out'' the relevant points from the vector
we could
multiply it by a square matrix3.9 with relevant numbers down its diagonals.
To make this more clear, let's consider the following matrix:
 |
(3.14) |
if we then multiply this matrix by the column vector:
 |
(3.15) |
we get out
 |
(3.16) |
At which point you go ``duh, Paul, that's because it was the
identity''. Well, yes, it was. However, if we wanted to ``pick out''
the bottom two elements of the vector we would use the following
matrix:
 |
(3.17) |
and we get
 |
(3.18) |
So what? you may ask. Well, look at the vector output. It has what
were the bottom two elements now in the top two positions of the new
vector, and has therefore picked out the elements that we wanted. It
has also shifted the elements of the vector up one (in some sense).
As we will hopefully see soon, this is a handy property that we will
use. Now, imagine that each element in the vector corresponds to a
point in space. Also imagine that we want to calculate some function
such that the new ``current point in space'' is equal to the
difference between the points in space on either side of it. Using
the vector we have at the moment, we therefore want the middle element
(
) to become
. We don't know what the other elements
should become at this stage since there is no point ``outside'' them.
So we want a vector output that looks something like this:
 |
(3.19) |
We could do this by using the following matrix:
 |
(3.20) |
Let's see if it works...
 |
(3.21) |
Well, it did basically what we wanted. The central element is now
equal to
, but the top element is
and the bottom
element is
--why is this? Well, imagine that there are zeroes
above and below the vector. So, to calculate what the top element
would be, we would have ``something like''
for the top element
and ``something like''
for the bottom element. Hence we get
the output we see in Equation (3.21).
Note that the process here is much like what we want to do with the
diffusion equation, namely: add the left- and right-hand points of a
vector and subtract twice the central point. Using the
(oversimplified)
matrices above we would do something
like this:
 |
(3.22) |
From the central element of the output vector we can see that this has
implemented what we wanted to achieve:
--look like the diffusion equation? Now we hopefully have a feel
for the structure of the
matrix for the diffusion equation.
Another way of looking at this is if we take the right-hand side of
the discretised diffusion equation:
 |
(3.23) |
then we can rewrite it as
 |
(3.24) |
where the
are the elements of some matrix
whose
elements can be written as
 |
(3.25) |
where the
are Kronecker delta functions and are equal
to 1 if and only if
; zero otherwise. If we now think of the
in the discretised diffusion equation as elements in a column
vector, we can rewrite the diffusion equation in the following form:
 |
(3.26) |
We wish to find the value of the vector
at the next point in
time, which is at
, hence we solve this equation for
:
where
is the identity matrix and
is just a matrix
to make the equations look nice and simple. So, our differential
equation problem has reduced to finding the
matrix and then
constructing the
matrix from that and then repeatedly
applying
to evolve the vector
. This in its
essence is all one has to code to use this representation.
Now, given that we have the boundary conditions that the function is
constant at the left- and right-hand edges (Dirichlet boundary
conditions) and are that they equal to zero, we construct the
following
matrix:
 |
(3.30) |
For an
vector (at time instance
) such as
 |
(3.31) |
verify for yourself that one application of the matrix
onto
gives
 |
(3.32) |
Notice how the top and bottom rows of zeroes in
ensure that
the ``edge'' elements of
stay zero. Thus the boundary
conditions can be made implicit in the
matrix. Handy eh?
What if we wanted periodic boundary conditions? Such a physical
example would be if we wished to model the diffusion of a wave through
time and space. So, if we had periodic boundary conditions, we could
let the wave travel across the ``window'' in space we have defined (to
the left, say) and it would appear from the right traveling to the
left. This would allow us to let the wave ``see''
a longer ``distance'' without having to have really large
windows in space. To do this with a variant of the
matrix
we would have to think carefully about the problem, and then realise
how the
matrix acts upon the
vector in an
element-by-element fashion. You may wish to verify that the
matrix that would give diffusion equation type behaviour with
periodic boundary conditions is
 |
(3.33) |
Note the 1's in the top-right and bottom-left corners. They are like
where the
matrix has ``wrapped'' around from the other side
of the matrix. It is this ``wrapped around'' kind of structure in the
matrix that gives the periodic nature of the boundary
conditions.
What are the advantages of using this matrix scheme? Well, your code
is a lot easier to read, and a lot easier to change. The main bit of
mental work on the programmer's part is in calculation of what the
matrix should be to apply to the
vector. Then,
inside the main loop, all one has to do is have a line saying
something like:
A = M*A;
to evolve the solution. It is literally that simple.
Ok. I hope that you have a bit of a grasp of the matrix
representation of differential equations now. Using this form for the
equations allows me to be somewhat less verbose in my explanations,
and makes some of the mathematics a bit more obvious. We go on to
investigate the implicit FTCS scheme in the next section.
Footnotes
- ... matrix3.9
- Why square? Well, we will get
back a vector with the same dimensions as before after applying the
matrix to it.
Paul Cochrane
2002-04-18