ASSIGNMENT 2.

-------------

 

Mail to: HCAB on MUSICB from your HC-- MUSICB code

Assignments mailed from any other E-Mail account will be

IGNORED !! (i.e. Receive a grade of ZERO!!)

TA: Maxim

Weight: 20

Due Date: 2nd October

 

This assignment has to be done in FORTRAN 90, using the LAHEY

compiler, which you can download for free from

www.lahey.com

 

or this is available in the EMF.

See the documentation on the LAHEY website for installation

and running programs on your own machine. Note your FORTRAN

90 source code should be the ELF90 directory with the compiler

for easy operation.

 

NOTE: Look at the NOTES on MUSIC B for doing this and the

other assignments.

 

 

In this assignment you are to calculate the sum defined as follows:


             x2           xn
z = 1 + x + ---- + ... + ---- + ... 
             2!           n!

The sum is considered accurate enough when term

                   xn
                  ---- < 0.001
                   n!

that is, you should stop calculating the sum when the above condition

is satisfied.

You should calculate the sum for the following values of x:

1.0

2.0

3.6

0.8

5.0

Print out the sum and the number of terms used to calculate the sum

for each given value of x.

For example, sum

                    x2      x3
           1 + x + ---- + ----
                    2!     3!
has 4 terms.

Input data should be read from data file using READ command in a loop. You

should stop upon reading value -1.0. So, your data file should look like:

1.0

2.0

3.6

0.8

5.0

-1.0

To read data from data file run your program as follows:

your_compiled_program.exe < datafile

Your output should look like:

z = ... number of terms = ...
z = ... number of terms = ...
z = ... number of terms = ...
z = ... number of terms = ...
z = ... number of terms = ...

Good luck.