PHYSICS 580 Spring 2005

Fortran Example #3 due

Write a short program that integrates, using the trapezoidal rule, a function. The program will give a choice of three functions: sine, cosine, and ln (natural log). The program will ask for the range and for the number of points.

When choosing your function, identify by the number (e.g., 1=sine, 2 = cosine, 3 = ln). The program must use control structures (IF) and must loop back and ask again if the user does not use 1,2, or 3.

If the user chooses the ln function, the program must also
check that the interval is strictly positive (because ln is not defined for
negative numbers).

Using the IF statements, fill an array with the chosen function. Then use a single DO loop to perform the integration; that is, do not write a separate integration loop for sine, cosine, or ln. You may model your integration loop directly on the example I have provided.

To make identification easier for me please use the convention lastname_ex3.f for your program. Also, your program should print out the following at the beginning:

This is fortran example 3.

Written by *your name here*.

to submit: first compress your file (this will help save formatting)

gzip lastname_ex3.f

this will produce a file lastname_ex3.f.gz

attach this to an e-mail to: cjohnson@sciences.sdsu.edu