Lab7
Math 181 Computational Mathematics
10/99, 3/01
E. A. Robinson

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

lab61.jpg

We are going to look for a solution lab62.jpg defined on the square lab63.jpglab64.jpg satisfying a boundary condition of the form

lab65.jpg

lab66.jpg

lab67.jpg

lab68.jpg

where lab69.jpg and lab610.jpg are four more or less arbitrary given functions defined on lab611.jpg .

The physical interpretation is that lab612.jpg is a square plate (say made out of metal), and the functions lab613.jpg and lab614.jpg correspond to a constant temperatures applied to the boundary. The solution lab615.jpg 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.



Our solution scheme will be what is called a relaxation method. It is based on the following finite difference approximation of the partial derivative

lab620.jpg

which when applied twice leads to

lab621.jpg

where lab622.jpg for some large lab623.jpg .

Thus the differential equation is approximated by a difference equation

lab624.jpg

lab625.jpg

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

lab627.jpg

Putting

lab628.jpg

the last version of the difference equation now becomes

lab629.jpg

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)

lab630.jpg

and

lab631.jpg

The implementation:

Think of of lab632.jpg as a lab633.jpg matrix.

The boundary conditions (above) describe the values of the entries lab634.jpg for i or j from lab635.jpg to lab636.jpg .

For convenience we will start by putting all the other entries lab637.jpg .

In one relaxation step we define

lab638.jpg

for lab639.jpg to lab640.jpg and lab641.jpg to lab642.jpg to define a new matrix lab643.jpg .

Once we have computed this, we then put lab644.jpg (do you see why this use of two variables is necessary?)

In practice you should apply relaxation steps until lab645.jpg and lab646.jpg 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:
 

What to pass in:
  1. An HTML document describing what you did and summarizing your results.
  2. Graphics.
  3. The source files for your programs (or worksheets, spreadsheets, etc.)
Put these in your "secret" web site.

Appendix: How to use 77 FORTRAN
 

  1. Download g77 fortran and install it. This means downloading 2 zip files: g77exe.zip (1.54Mb) and g77lib.zip (208Kb), and extracting them. It also means adding FORTRAN to the path by typing from a dos prompt something like (depending on where you installed FORTRAN)

  2.  

     

    > PATH=c:\g77\bin;%PATH%

    On your own computer you might want to add this to your "autoexec.bat" file.
     
     

  3. Here is a sample FORTRAN file diff.f  that implements the numerical calculation of the derivative of f(x)-sin(x)^2+1 using the "3-point" formula f'(x)=(1/2h)(f(x-h)-f(x+h)). To compile it you would type (from the dos window containing your FOTYRAN file)

  4.  

     

    > 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.



Comment:

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.