Performance Comparisons
In this lab we will compare the performance of two different implementations the same mathematical model. One implementation should be a conventional programming language (Fortran, C, C++, Basic, etc. This will be your choice. I provide some suggestions below). The other implementation should be either in Maple (a CAS) or MATLAB (again, your choice).
The model is a boundary value problem for the Laplace equation, using a simple relaxation method.
The model:
The Laplace equation is the partial differential equation

We are going to look for a solution
defined on the square
,
satisfying
a boundary condition of the form

where
and
are four more or less arbitrary given functions defined on
.
The physical interpretation is that
is a square plate (say made out of metal), and the functions
and
correspond
to a constant temperatures applied to the boundary. The solution
models the temperature in the entire plate after it has come to thermal
equilibrium.
This is perhaps the simplest of all partial differential equations, and its solutions are well understood (they are refereed to as harmonic functions). We will use the following boundary conditions in our model
gl(y) = -1+10y2-5y4
gr(y) = 1-10y2+5y4
fb(x) = x5-10x3+5x
ft(x) = x5-10x3+5x
Comment: This is such a simple example it is possible to solve
it exactly. Our interest here is more in the method.

which when applied twice leads to

where
for some large
.
Thus the differential equation is approximated by a difference equation

By multiplying both sides by
(twice) and solving, we obtain.

Putting

the last version of the difference equation now becomes

In other words, the solution function satisfies the condition that it's value at every point is an average of its neighboring values. This is a well known property of harmonic functions called the mean value property.
We want to solve this difference equation subject to the boundary condition(s)

and

The implementation:
Think of of
as a
matrix.
The boundary conditions (above) describe the values of the entries
for i or j from
to
.
For convenience we will start by putting all the other entries
.
In one relaxation step we define

for
to
and
to
to define a new matrix
.
Once we have computed this, we then put
(do you see why this use of two variables is necessary?)
In practice you should apply relaxation steps until
and
differ
by some predetermined error that you input (for example if you want 7 decimal
places you should set the error at .00000005).
Theoretical estimates of how many steps this will take can be obtained (using the theory of Markov chains), but we won't worry about that!
Assignment:
If possible, use the same computer as in Part 1. Be sure to use double precision arithmetic. If possible, have your program output its answer in a form that can be read by MATLAB (think about how you type numbers input into MATLAB) and plot your output using MATLAB.
. As you run both programs try timing them (with a watch). Also keep track
of how many relaxation's are necessary.Appendix: How to use 77 FORTRAN
> PATH=c:\g77\bin;%PATH%
On your own computer you might want to add this to your "autoexec.bat"
file.
> g77 -O2 -mpentium diff.f -o diff.exe
You can use this file as a template for your own FORTRAN program for the relaxation method from this lab. The compiled program diff.exe is also available for you to try out.
I used the WebEq 2.5 "wizard" program to make this web page. which converts the formulas into jpeg files. This was my first attempt at using this and it has a few rough edges. We will talk about TeX and its relatives next class in 2 weeks.