Your company is designing a new metal alloy. You have been asked to
write a computer simulation that calculates how heat passes through
this new substance. Your program will simulate the
following situation.
A thin rod, made of this new material, is placed between two heat
sources. Each end of the rod is in contact with one of the heat
sources. Each of the heat sources maintains a constant temperature,
but the two heat sources do not necessarily have the same temperature.
The rod has a uniform initial temperature and is completely insulated
from the surrounding atmosphere.
We will use a technique called the finite-difference method to
solve the problem. In order to determine the temperatures at
different points along the rod, we divide the rod into segments, each
of length h, as illustrated by the dashed lines in the figure. We
assume that the temperature within each segment is uniform.
This simplifying assumption is not always true, of course, but as the
number of segments becomes large, it approaches the truth.
Suppose, for example, that your program divides the rod into 1000 small
segments. Initially, the leftmost segment is the same temperature as
one heat source, the rightmost segment is the same temperature as the
other heat source, and the remaining segments are at the initial
temperature of the rod. Your program must then simulate the passage
of time by repeatedly calculating the temperature of each segment as
heat flows through the rod.
We will discuss how heat actually flows through the rod later in this
lesson, but for now think about the 1000 segments whose temperatures
we are calculating. Doing this requires 1000 variables which, using
techniques that you already know, will lead to a large and messy
program. Now imagine using 10,000 segments instead!
By using arrays, it is possible to come up with a solution that is no
more complicated for one million segments than it is for ten! Let's
see how.
Eric N. Eide
Hamlet Project
Department of Computer Science
University of Utah