CSCI 297 Assignment C
Statistics about a Function on an Interval
In this assignment, we are investigating the behavior of a specific function on an interval. We are interested in the maximum and minimum values (and where they occur) and in the average value.
We will do this by computing and examining the values of the function at a series of points evenly spaced across the interval. We will do it several times with different numbers of subdivisions.
This is somewhat more sophisticated than the previous assignments. We will be opening and closing the input file and output file. We will be using subroutines and a function.
What function are we using?
The function F we will use is defined as follows on the interval from X = 0.0 to X = 10.0. It is defined in several parts:
for X between 0.0 and 1.0, F(X) = -5.00 * X + 6.00
for X between 1.0 and 1.1, F(X) = 70.00 * X - 69.00
for X between 1.1 and 1.2, F(X) = -130.00 * X + 151.00
for X between 1.2 and 3.0, F(X) = 2.00 * X - 7.40
for X between 3.0 and 3.4, F(X) = 13.50 * X - 41.90
for X between 3.4 and 4.0, F(X) = 4.00
for X between 4.0 and 4.8, F(X) = -13.75 * X + 59.00
for X between 4.8 and 5.0, F(X) = 55.00 * X - 271.00
for X between 5.0 and 6.0, F(X) = -3.00 * X + 19.00
for X between 6.0 and 7.0, F(X) = 3.00 * X - 17.00
for X between 7.0 and 8.0, F(X) = 5.00 * X - 31.00
for X between 8.0 and 8.1, F(X) = -150.00 * X + 1209.00
for X between 8.1 and 9.0, F(X) = 8.00 * X - 70.80
for X between 9.0 and 10.0, F(X) = 2.80 * X - 24.00
This is what is called a "piecewise linear" function. Its graph is made up of a number of line segments.
What does the data look like?
Each line in the input contains one INTEGER value N.
Copy the data file into your directory. You can find it here.
Steps in the program
You will need to write a REAL-valued function subprogram to compute the function F defined above.
Your program should read each line in the input until it reaches the end of the file. The number N is the number of evenly spaced points we will use in the interval from X = 0.0 to X = 10.0.
Check for the possibility of N <= 0. If N <= 0, call a subroutine called ERROR to print a message saying we have a bad number of subdivisions. The only argument for ERROR is the number of subdivisions. Otherwise, do the following:
The arguments for FINDMAX should be the function F, the left endpoint L = 0.0, the right endpoint R = 10.0, the number of subdivisions N, a variable BIG to hold the maximum value and a variable BIGX to hold the value of X where the maximum occurs.
How does FINDMAX work?
The arguments for FINDMIN should be the function F, the left endpoint L = 0.0, the right endpoint R = 10.0, the number of subdivisions N, a variable LITTLE to hold the minimum value and a variable LITTLEX to hold the value of X where the minimum occurs.
FINDMIN works very much like FINDMAX except that we look for F(X) < LITTLE.
The arguments for FINDAVE should be the function F, the left endpoint L = 0.0, the right endpoint R = 10.0, the number of subdivisions N and a variable AVE to hold the average value.
How does FINDAVERAGE work? Use a local variable SUM.
Programming Notes
The name of your source code file should be "progC.f90".
The output should have a page heading and column headings.
Your output should have a page heading and column headings. Double-space between lines. In printing maximum and minimum values, use 2 digits to the right of the decimal point and use a field wide enough to avoid printing asterisks. The output should all fit on one page.
You will probably not exactly the same values for the statistics each time. The answers do depend on the value of N.
Use CHARACTER(n) variables to hold the messages, column headings and page headings you use in your report. Initialize them with their values.
You should pass the function F to the first three subroutines as an an argument. You will need an EXTERNAL statement in the main program to do this. You may need to read about this.
Use the WRITE statement and the general READ statement (see section 5.4 in our textbook) to do your reading and printing.
Include the date and your name in the page heading. Center your output neatly on the page.
Your program should be well structured and properly documented. You may want to use more subroutines as well. Do not use any GO TOs. Do use IMPLICIT NONE.
Assign the input file the unit number 9. After you are done with it, CLOSE it. The name of the input file is "dataC.txt".
Assign the output file the unit number 10. After you are done with it, CLOSE it. The name of the output file should be "outputC.txt".
If you have trouble deciding on the steps to use, try working through an example by hand, such as N = 4.
After compiling and linking your program as usual (and fixing errors, if any), run it as usual.
What does this function look like anyway?
If you want to try to graph Y = F(X), you need to plot some points and connect the dots:
X Y
_____ _____
0.0 6.0
1.0 1.0
1.1 8.0
1.2 -5.0
3.0 -1.4
3.4 4.0
4.0 4.0
4.8 -7.0
5.0 4.0
6.0 1.0
7.0 4.0
8.0 9.0
8.1 -6.0
9.0 1.2
10.0 4.0