Computer Science
1107
AN INTRODUCTION
TO FORTRAN
PROGRAMMING
FOR SCIENTISTS AND
ENGINEERS
Fall 2001
Programming Assignment 8
Due date: Monday, November 5, 2001
Objective:
To explore writing FORTRAN 77 programs using functions and subroutines. All
functions used should return a single value without changing argument values,
and subroutines should only return
values by changing the values of the arguments as discussed in class.
A. Text Problem 8, Page 364.
- Use functions for all of the equations given in the problem.
If you find it useful, you may use
or
modify portions of the trapezoid approximation program
which we
developed in class.
Here is the trapezoid approximation program.
- Create a hand-drawn flow chart for the entire
program using the
appropriately
shaped boxes for start-stop, Input/Output, and computation as discussed
in class OR write out the algorithm for the entire program using
pseudocode which should be written out by hand, not typed.
- Write the FORTRAN program, naming the source
code file lab8a.f and including an explicit list of all
variables as well as a short description of the problem in
a documentation section using comment
lines at the beginning of the program. Be careful to choose the types of
your variables appropriately and to include the names and student
numbers of all authors in the documentation section. If you use or modify
the code provided above, be sure to note this in your documentation.
- Check
your results before creating your script file.
B. Dice Problem and Randomness.
In this problem, you will not be writing code. Instead you will be exploring
the results produced by a program which already compiles and runs correctly.
- Do not make a script file for the exploratory portions (1-5) of this
problem.
- Save the program dice.f into your itlabs
account. Compile this and run it.
- This program is designed to simulate a pair of dice rolling. With two
fair dice, the expected probabilities are 1/36 for each of the following 36
outcomes:
(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6),
(2, 1), (2, 2),
(2, 3), (2, 4), (2, 5), (2, 6),
(3, 1), (3, 2), (3, 3), (3, 4), (3, 5),
(3, 6),
(4, 1), (4, 2), (4, 3), (4, 4), (4, 5), (4, 6),
(5, 1), (5, 2),
(5, 3), (5, 4), (5, 5), (5, 6),
(6, 1), (6, 2), (6, 3), (6, 4), (6, 5),
(6, 6).
This means that the probability of rolling a pair (or spot) that sums to
10 is 3/36 = 1/12 since the sum of 10 can be obtained
by rolling (4, 6), (5, 5), or (6, 4).
- Run dice.f sufficiently many times with sufficiently high numbers
of rolls to discuss in a few paragraphs how "random" the random number
generator is in this program.
As you increase the numbers of rolls, do the probabilities seem to
be approaching the expected probabilities?
- Edit the program and comment out the PRINT line which prints
each roll of the dice, and then recomplile the program.
- For this problem, you do not need to include the program code or the
compilation in your
script file--just include the runs. Begin the script file and run your edited
program sufficently
many times to demonstrate the reasonableness of your conclusions.
C. Text Problem 22, page 464.
There is an error in the textbook, on page 464. The last line of the question should read
"Use your program to compute the voltage (not current) passing through the capacitor as described in Exercise 8 of Section 6.4." Use your program to find the voltage for a capacitance C of 5 F and a time interval T of 4 seconds.
In this problem, you may use subroutines and functions from either of the
previous two problems, but it is required that you write at least one new
subroutine to do the Monte Carlo integration.
- Create a hand-drawn flow chart for the program using the appropriately
shaped boxes for start-stop, Input/Output, and computation as discussed
in class OR write out the algorithm for the entire program using
pseudocode which should be written out by hand, not typed.
- Write the FORTRAN program, naming the source
code file lab8c.f and including an explicit list of all
variables as well as a short description of the problem in
a documentation section using comment
lines at the beginning of the program. Be careful to choose the types of
your variables appropriately and to include the names and student
numbers of all authors in the documentation section.
- Check your results before creating your script file.
Then hand in the following for each of the three problems:
- All required flow charts OR pseudocode.
- A script file containing all of the
following as required:
- A printout of the source program obtained by using the UNIX cat
command
- A compilation of the program obtained by using the f77
command
- Results of execution the program with the
given data sets obtained by using a.out
- The discussion from problem B.
- A paragraph discussion regarding the utility of subprograms,
namely functions and
subroutines.
Recall: For this and
all programming assignments you should follow good software engineering
principles including using good structure, documenting your program with
comments, and using
meaningful names for variables. Failure to do this will lead to reduced
credit.
For this and subsequent assignments, you have the option of
working in teams of two people. In this case, turn in one copy of your
results with both names and student numbers included on every page of
every item
submitted.