Due on Tuesday, Oct. 16.
A Fortran source file, say prog.f90, can be compiled and linked into an executable program called prog with the command
gfortran prog.f90 -o progon the ECA computers or with
g95 prog.f90 -o progif you are using G95. (Unlike C compilers, which almost always can be invoked with cc, Fortran compiler names vary.)
On many, but not all, Fortran implementations, the suffix .f indicates source in fixed format and the suffixes .f90 and/or .f95 indicate free-form source. We will use free-form source; fixed-form is considered obsolescent. Both G95 and Gfortran support this convention.
Here is a sample module and another program to generate normally distributed deviates. They illustrate some aspects of Fortran syntax in more detail.
You will email this assignment. You will create three programs, each of which is entirely contained in a single source file. Call your source files
stats.f90 (Exercise 1)You will package these files into an archive (file of files) using the tar command as follows:
linlsq.f90 (Exercise 2)
quad.f90 (Exercise 3).
tar cf hw5.tar stats.f90 linlsq.f90 quad.f90This command creates a file called hw5.tar.
Email your assignment with a subject line of the form
Your_name MAT 420 HW5to mat420hw at gmail.com. Include hw5.tar as an attachment. This assignment is due on Tuesday, Oct. 16.
The usual homework policies apply. You may work with a partner and turn in a single assignment with both of your names on it.
Exercise 1. Here is a sample program that reads one number per line and prints the total. (Compile it and try it out.) Modify the program so that it prints
mean standard_errorinstead. (One estimator of the standard error is the square root of E(X2)-(E(X))2, where E(X) is the mean of X.) A single main program suffices for this exercise.
Exercise 2. Here is a skeleton of a program that reads in a number, n, followed by n lines of input of the form
x yComplete the subroutine linlsq so that it computes the slope and y-intercept of the linear least-squares regression line through the xy data. (Here are some formulas that you can use.) Compile and test your program (call the executable linlsq) on appropriate data.
Exercise 3. Write a program that, given the values a, b, and c on a single line read from the standard input, prints the roots of the polynomial
ax2 + bx + c = 0using the quadratic formula. A single main program suffices.
Copyright (c) 2007 by Eric J. Kostelich. All rights reserved.