General instructions for writing programs

As part of your assignments in this course you will often be required to write computer programs to solve a class of particular problems. Here are some general instructions on what I expect for these parts of the assignments.

Such programs must be written in either C or FORTRAN since we will be using IMSL routines in one of these languages (see IMSL sheet).

When you hand in the assignment, it must contain:

- a copy of each computer program used;

- a copy of the output(s) of each of the programs;

- additional written comments as necessary to interpret the output or explain the program.

The algorithm to solve the given problem must be written as a separate subprogram which is called from a main program. All input and output should be done in the main program or in a separate subprogram designed for this purpose. If several different cases are calculated for the same program, the output should be formatted for easy comparison of the various results. Codes should be written in a general form, i.e. for N dimensions rather than 2 or 3 dimensions.

All calculations using real numbers must be done in double precision. In FORTRAN this means using REAL*8 numbers; you may use an IMPLICIT to make this the default. For most C compilers this is the default for real numbers. All constants such as ? must also be given to this accuracy. For example, an easy way to get ? to the required number of digits is to calculate 4 tan-1(1) using the correct type of arithmetic. Make sure that all your input is accurate as well. Thus if you are required to divide an interval (a, b) into N subintervals of length H do not input H itself but rather N and calculate

H = (b - a)/N. In programs which implement an iterative procedure always put an upper limit on the number of possible iterations to prevent the program from running indefinitely. Also do not store the iterates. Keep only the last one or two at each step.

All programs must be thoroughly documented by adding comment lines in the program itself. Explain what each step of the program is designed to do, define all variables used and refer to the particular algorithm which is the basis for the program if it is not obvious. If you are simply coding a given algorithm (from Burden and Faires, for example) you do not have to define the variables in the subprogram provided the same notation is used as in the algorithm. However, all variables in the main program must be defined in comment statements.


In general, I expect some analysis of the output. For example, if the algorithm has one or more parameters which are to be chosen (e.g. step size, degree of polynomial, number of terms, starting values) then the problem should be solved for several sets of these parameters. This means you have to choose values which will highlight the dependence of the algorithm on the parameters and demonstrate the behaviour of the error. Having obtained the results you must add (written) comments analyzing the error by comparing to known solutions or using the known dependence of the parameters. Finally you should draw some general conclusions about the algorithms (what are their strengths and weakness, how does the error behave, etc.) and point out any unexpected behaviour.