Math 171 Spring 2005, Lab 8

Due Saturday Saturday, February 26, 11:59 P.M.

  1. Overview
  2. Assignment
  3. Hints

Overview

The purpose of this lab is to introduce you to using DO loops in Fortran. Additionally, you will gain practice implementing two fundamental algorithms of numerical mathematics (series approximation and bisection).

Top

Assignment

Write a fortran program called pie_approx that calculates either pi or e (according to the user's specification) using the maximum possible precision. Your program must satisfy the following requirements:

Top

Hints

  1. To start out, just write a skeletal program that prompts the user for which calculation they want. Put in an IF-THEN-ELSE statement that prints a message saying something like "the calculation of e will go here". In general, any code that serves as a placeholder is called a stub.
  2. The calculation of e is easier. So, your next step should be to implement a DO loop (inside the e clause of the IF statement) for the power series expansion of the exponential function. Make sure this calculation is correct to the maximum number of digits of accuracy.
  3. Now get your power series for sin(x) working. Don't worry about the bisection method yet, just try your calculation for several different values of x and make sure they come back correct.
  4. Finish by adding an additional DO loop for the bisection method. This loop should surround your power series approximation to sin(x). If you set up the calculation correctly, you shouldn't have to change anything inside the inner loop (except the indentation level).
  5. Test your program by checking against the various approximations to pi and e that can be found on the web.
  6. Finally, go back and add the WRITE statements for the requested stats on your program's performance if you haven't already done so.

Top

Back to the course information page