Search


CS 270 Home Page



Introduction to Numerical Computation



Spring 2010


This course has two main goals: to teach the student the basics of programming in the Fortran 95 language and to use that language to find numerical solutions to mathematical problems, especially problems of interest in science and engineering. In order to do this, a good deal of time is spent on studying elementary numerical analysis. Good software engineering techniques are emphasized in the programming portions of the course. Mathematica and hand calculators are used to help in solving several types of numerical analysis problems. However, the Fortran work that forms the bulk of the course is done on the CIS department's Linux server. You can access this server from any of the CIS lab PCs or from your PC in the dorms if you get appropriate software (such as SecureCRT, TeraTerm, or PuTTY) as described on the server usage page. Off campus access is sometimes possible. See Br. David to investigate that possibility.

Meeting Times

  • Tue, Thurs 8:30 - 9:45 am, Physics 01 (CIS lab)

Further Information

  • The Course Syllabus
  • Tentative Course Schedule
  • Grading Guidelines
  • CIS Lab Schedule
    See when you can use the lab to do your homework.
  • mathworld.wolfram.com
    Contains a wealth of resources, including some on numerical methods.
  • Dr. Botsko's Mathematica Web Page
  • Wolfram Mathematica Learning Center
  • Information on UNIX Editors
  • For information on available commands on our Linux server, enter the following at the comand prompt:
    topic
    topic 12
  • See the Server Usage page
    For information about our server and the software you can use to access it.
  • The easiest way to compile a Fortran 90 program on our Linux system is as follows, where we assume that the program is named series.f90:
    build90 series
    The build90 script will link in the library of numerical subroutines if needed. It will put the executable in a file with the name series (without the .f90). You then run the program by entering ./series at the command prompt.
  • Information on Well-known Series
  • Power Series
  • Of interest especially to engineering students:
  • Fortran programs:
    Anyone can copy these examples when viewing them in a browser. Students in this class can also copy them at the commmand line as in the following two examples:
    cp /home/cs270/trap1.f90 . (The dot is necessary. It represents the current directory. Thus we will copy the file to the current directory. The filename will stay the same.)
    cp /home/cs270/convert.f90 myconvert.f90 (This will copy to a new filename in the current directory.)
    • aboveavg.f90
      Illustrates the use of a 1-dimensional array.
    • arith1.f90
      Prints the largest integer, the largest plus 1, etc.
    • arith2.f90
      Tries division by zero, etc.
    • arith3.f90
      Experiments with adding large and small numbers, as well as adding in different orders.
    • arith4.f90
      Reports on characteristics of integers and reals.
    • arith5.f90
      Reports on characteristics of integers and reals of various kinds.
    • average1.f90
      Averages a list of numbers with 0 used to end data entry.
    • average2.f90
      Uses a WHILE loop to solve the same problem.
    • bsectst1.f90
      Uses bisection algorithm to find a zero of a function.
    • bsectst2.f90
    • bsectst3.f90
    • convert.f90
      Simple program to convert from Fahrenheit to Kelvin.
    • deriv1.f90
      Program to compute a derivative at a point.
    • epsilon1.f90
      Estimates the machine epsilon.
    • epsilon2.f90
      A minor variation on the previous program.
    • epsilon3.f90
      Shows how to use a subroutine.
    • factorial.f90
      Prints the factorial of each nonnegative integer entered.
    • integ3.f90
      Uses the numerical subroutine library to integrate sin(x) from 0 to pi.
    • leqtest.f90
      Uses Gaussian elimination with partial pivoting to solve a system of linear equations.
    • leq.in
      Input data file for the previous program.
    • linear1.f90
      Uses a library subroutine to solve a system of linear equations.
    • linear2.f90
      Solves a system of 3 linear equations in 3 variables via simple-minded elimination and back substitution.
    • looptest.f90
      Finds the limits for integer and real loop control variables.
    • machine1.f90
      Looks up and prints the values of various machine constants.
    • machine2.f90
      Looks up and prints the values of some other machine constants.
    • maxmin.f90
      Finds where max and min are in a list of integers.
    • multiply1.f90
      Simply multiplies two numbers.
    • multiply2.f90
      Prints some products and quotients.
    • newton3.f90
      Uses Newton's method for finding a zero of a function.
    • newraph3.f90
      Uses Newton-Raphson method for finding a zero of a function.
    • ode1.f90
      Solves an ordinary differential equation via Euler's method.
    • ode2.f90
      Solves another ordinary differential equation via Euler's method.
    • ode3.f90
      Uses Taylor's series to solve an ordinary differential equation.
    • ode4.f90
      Uses Taylor's series to solve another ordinary differential equation.
    • quadeq1.f90
      Solves a quadratic equation via the quadratic formula.
    • readfile.dat
      Data file to accompany the following program.
    • readfile.f90
      Shows how to read numbers from a formatted file.
    • series1.f90
      Finds a partial sum of the series 1+ 1/2 + 1/4 + 1/8 +...
    • series2.f90
      Finds sin(x) for a particular value x by using the power series for sin(x).
    • series3.f90
      Uses an array so that terms can be added from smallest to largest.
    • series8.f90
      Program to investigate a Fourier series that converges to 1 on (-1, 1), to 0 at 1, to -1 on (1, 3), etc.
    • series15.f90
      Uses a Taylor's series approximation to integrate sin(x) from 0 to pi.
    • sqroot.f90
      Prints a table of square roots. More importantly, it shows how to use a 1-dimensional array.
    • subroutines.f90
      Illustrates how to write and use subroutines. Really short subroutines are used in this and the next two examples in order to keep the examples simple.
    • subroutines2.f90
      Illustrates how to write and use subroutines. This one has a subroutine with an INOUT parameter.
    • subroutines3.f90
      Illustrates how to write and use subroutines. This one replaces one of the subroutines in the previous two examples with a function.
    • trap1.f90
      Uses the trapezoidal rule to integrate sin(x) from 0 to pi.
    • trap2.f90
      Double precision version of trap1.f90.

Examples and Class Materials

Help is Available

Note on Flu


Because of the possibility of H1N1 and other types of flu affecting us on campus, please practice good hand washing, etc. If you get the flu, please notify me by phone or e-mail and stay home for 24 hours after the fever has gone. Check with me about what you miss. You will not be penalized for missing class in this situtation. It is better to stay away from class and not spread the flu when you are ill.

Homework, Labs, etc.

  • Lab 0 will be done in class on Thurs, Jan 14.
  • Homework 1: Do problem 2-15 in the text by writing a Fortran program under the name hw1.f90. Due anytime Tue, Jan 26. Hint: the correct answer should be about 0.140 kilograms = 140 grams. Use the senddc script to send me your program as follows:
    senddc hw1.f90
  • Homework 2: Do problem 2-26 in the text by writing a Fortran program under the name hw2.f90. You may do this problem either individually or in pairs. In the latter case, just submit one homework for both students, but be sure both names are in the comment section at the top. Due anytime Tue, Feb 2. Use the senddc script to send me your program as follows:
    senddc hw2.f90
  • Homework 3: Do problem 3-12 in the text by writing a Fortran program under the name hw3.f90. Do this one individually, please. Due anytime Tue, Feb 9. Use the senddc script to send me your program as follows:
    senddc hw3.f90
    Note that the text has a typo. They meant to reverse the values of n1 and n2 between the two sets of data. Thus, use this test data:
    a) n1 = 1.0, n2 = 1.7, theta = 45 degrees
    b) n1 = 1.7, n2 = 1.0, theta = 45 degrees
    It sounds like they want you to run your program twice to get the two results. Thus, they don't want the above numbers to be hard-coded; they should be entered by the user when running the program.
  • Since 8:30 classes are cancelled on Thurs, Feb 11, read chapter 4 on your own.
  • Homework 4: Do problem 4-22 on page 178. Name your program hw4.f90. You may do it individually or in pairs. If you do the problem in a group of 2, put both names in the comment section and just have one of you submit the program. Send it to me with:
    senddc hw4.f90
    The program is due by Wed, Feb 16 (anytime that day) -- as long as more bad weather does not delay things further!
  • Homework 5: This is a set of small group problems on series. The work will be presented by the groups in class on Thurs, Feb 18 and Thurs, Feb 25. The two people in each group should check with each other in person, by email, phone, etc. as needed. If you get stuck or are unsure if you have adequately answered your problem, check with Br. David. If your problem involves writing a Fortran program, use senddc to send it to me.
  • For Thurs, Mar 11, read chapter 5.
  • For Tue, Mar 16, do the second small group problems on series. See the handout given in class (or follow the link) for the problems and who works on what. The presentations are to be done in class on Mar 16.
  • Homework 6: For Tue, Mar 23, do the following problem individually. Copy the hw6.f90 program from the Mar15Examples folder on the course network drive. Then modify the program so that it prints out partial sums for the geometric series 1 + x + x^2 + x^3 + x^4 + .... The program should read its input from the text file hw6.in and write its output to the file hw6.out (except that any error messages should be written to the screen). The hw6.in file should contain any number of lines of the form:

    x-value number_of_terms

    For example, hw6.in might contain:

    0.5 4
    0.5 20
    0.7 22

    The program should then find and print to hw6.out the first 4 partial sums of the geometric series when x = 0.5, next the first 20 terms for x = 0.5, and finally the first 22 terms when x = 0.7. Each of these 3 reports should be preceded by a header like this one for the first report:

    For x value 0.5 the first 4 partial sums are:

    Between reports there should be a blank line to separate them. If either hw6.in or hw6.out fails to open, print an error message on the screen. Also, if a read fails, print an error on the screen. You may skip checking to see if a write fails to work. Use our efficient method to compute x^k from the previous term; do not use x ** k. For the above input file data, the output would look something like this:

    For x value 0.5 the first 4 partial sums are:
    0.10000000E+01
    0.15000000E+01
    0.17500000E+01
    0.18750000E+01

    For x value 0.5 the first 20 partial sums are:
    (20 lines of numbers appear here)

    For x value 0.7 the first22 partial sums are:
    (22 lines of numbers appear here)

    Send your hw6.f90 program to me with:
    senddc hw6.f90

Exams

  • Final Exam: Thurs, May 6, 8:30 - 10:30 am

Instructor: Br. David Carlson





Maintained by: Br. David Carlson
Last updated: March 15, 2010
Disclaimer