Accessibility

12.010 Computational Methods of Scientific Programming

 

Instructors: T. Herring (tah@mit.edu), Chris Hill (cnh@plume.mit.edu)

 

This course introduces programming languages and techniques used by physical scientists: FORTRAN, C, C++, Matlab, and Mathematica.  Emphasis is placed on program design, algorithm development and verification, and comparative advantages and disadvantages of different languages.  Students first learn the basic usage of each language, common types of problems encountered, and techniques for solving a variety of problems encountered in contemporary research: examination of data with visualization techniques, numerical analysis, and methods of dissemination and verification.  No prior programming experience is required.

 

Prerequisite: 18.01, 18.02, 8.01

 

Aim of course:

The aim of this course is to give students an introduction to the uses of computer languages in the analysis of contemporary scientific problems.  The course covers both conceptual areas of converting a problem to be solved into a computer-based solution, and specific aspects of individual languages and the types of problems they are best suited to solve.   Emphasis is placed on the importance of structure, documentation, and levels of "user-hostility" of program interface.  For each language, the basic syntax and structure of the language is covered with examples drawn from real applications.  The major toolboxes and libraries, interfacing techniques and platform specific issues are also addressed. 

Homework will be assigned for each of the languages and there will be a common project developed during the course that students will solve using the language of their choice.   The final class will be used to compare the different solutions developed.  Homework grading will be based not only on completing the assigned task but also on solution structure, robustness, human interface, documentation and transportability. 

 

This class has no final exam.

Class grading: 80% homework, 20% final project

 

Office Hours for Prof. Herring; Tuesday 1:00-2:00 pm

 

There is an open courseware version of this course.


 

Course Outline:

 

Class

Date 2011

Instr.

Topic

1

09/08

TH

Introduction: Problem formulation, algorithm development, algorithm implementation, and algorithm verification. Structure and documentation

2

09/13

CH

3

09/15

CH

Fortran: "Formula Translation".  Program creation, compilation and linking, variables and parameters, flow control, subroutines and functions.  Structure and documentation.  Use of libraries, internal and external communication, and interaction with other languages. Fortran: Implementation issues: Compilation errors, segmentation violations, Not-a-Number (NaN), Input/Output (IOSTAT) errors, Runtime errors.  Transportable code, standard extensions. Fortran 90 differences and similarities to Fortran 77

4

09/20

TH

5

09/22

TH

6

09/27

TH

7

09/29

TH

8

10/04

TH

C for Scientific uses. Representation of data through arrays, pointers, and data structures.  Function calls, argument passing and scoping rules, IO, profiling, system calls, and signals.

C++ objects. Encapsulation and inheritance, polymorphic operators.

9

10/06

TH

10

10/11

TH

11

10/13

TH

 

 

 

12

10/18

TH

Mathematica. What it is and what it can do; structure of Mathematica; symbols, exact numbers, and machine numbers; lists, vectors, and matrices

Working with Mathematica: numerical calculations, symbolic calculations, and graphics.  Importing and exporting information

13

10/20

TH

14

10/25

TH

MatLab. "Matrix Laboratory". Matlab syntax, workspace, variables.  Script M-files, IO, control flow, debugging, and profiling tools.  Object-oriented programming

Matlab applications, polynomials, interpolation, integration, differentiation, ODE.  Graphics, 2-D, 3-D, Graphical User Interface (GUI)

15

10/27

TH

16

11/01

TH

17

11/04

TH

18

11/08

TH

Python scripting language program

19

11/15

TH

20

11/17

TH

Advanced graphics in Matlab, 3-D representation and exportable animations.

21

11/20

TH

Ordinary differential equation (ODE) solutions used Matlab and Mathematica

22

11/29

CH

Advanced Topics: Parallel computing with large memory and large numbers of CPUs.

Advanced topics: Parallel MATLAB.

Discussion of final projects.

Order of the presentations will be decided in the last class.

23

12/01

CH

24

12/06

CH

 

12/13

All

Final Project Presentations

 


 

Instructors: TH: T. Herring tah@mit.edu,; CH Chris Hill cnh@plume@mit.edu

 

 


Lecture Notes 2010 (shaded) and 2009 (non-shaded)

 

The lecture notes are converted from Microsoft Power Point documents portable document format (PDF).  The most complete version of the documents is the power point files, which we make available for each lecture.  Lecture notes are added as the class is taught.   Check the date on the lecture notes to make sure you get this year’s version.

 

Lecture 01: Class introduction; overview of languages; Program development

 Lec 01 PDF        Lec01 Power Point       Thursday, September 09, 2010.

 

Lecture 02: Discussion of aspects of computers and their operation.  An example is given of program development for a simple case of computing the area of a figure.  In this lecture there are notes that appear in the power point document.  (These notes are often important for doing the homework and are not in the PDF file).

Lec 02 PDF         Lec 02 Power Point      Tuesday, September 14, 2010

In the lecture notes the poly_area.f Fortran program is referred to.  This program implements the area determination algorithm discussed in the lecture. Links that are in the notes for this lecture:

http://www.webopedia.com/TERM/B/big_endian.html.

http://mathworld.wolfram.com/GreensTheorem.html

http://www.psc.edu/general/software/packages/ieee/ieee.html

 

Lecture 03: Started FORTRAN (Formula Translation).  Went through the basic elements that make up this language.  An on-line version of a Fortan77 manual can be found at the www.fortran.com.  In reading these notes, you should think about operations you want to do and what command or commands do you use to do that.  The list on Fortran intrinsic functions can be found at http://www.fortran.com/fortran/F77_std/rjcnf0001-sh-15.html - sh-15.10

Other links to look at:

http://www.engin.umd.umich.edu/CIS/course.des/cis400/fortran/fortran.html

http://en.wikipedia.org/wiki/Fortran

Lec 03 PDF         Lec 03 PowerPoint       Thursday, September 16, 2010

 

Lecture 04: Continued with showing the elements of the Fortran and more detail on the typically encountered features of the language. Topics covered: subroutines and functions; intrinsic functions; constants and variables; input output with open/close, read/write, formats; character strings.

Lec 04 PDF         Lec 04 PowerPoint       Tuesday, September 21, 2010

The links in this lecture were to fortran and intrinsic functions above. 

The following programs give examples of different Fortran codes:

loops.f                               demonstrates loops

ifs.f                 demonstrates if statements

inout.f                        demonstrates file input and output

subs.f                         demonstrates subroutines and functions.

To download programs, right click on link and "save link target as".   With one-button mouse use <ctrl><click> on link.

 

The programs poly_area.f and vars.f are also used.

 

On Athena to use these programs:

ssh –X linerva.mit.edu

% add gcc-4.0  # This is probably not needed

% gfortran poly_area.f –o poly_area

% poly_area

(Note: do not type %, it is meant to be the prompt).

 

PC Instructions

If you are familiar with installing software on your PC and know lots about the Windows system you can try to install g77 from the link below.  (We don’t know if this will work on Vista).   There is a “click here” for instructions button that you should read first to see if you understand the instructions.

Below is a link to Fortran (g77) for PC

Link to PC Fortran 77

Below are alternative instructions (these require about the same amount of knowledge as the instructions above).

Alternative is to add cygwin to your PC (linux running on PC).  Download cygwin from

http://www.redhat.com/services/custom/cygwin/

Use cygwin_setup to get gcc, g77 and nedit

Also needed is

http://ist.mit.edu/services/software/xwin32/94

which is the Windows X-window system.  (Needed for nedit)

When using X-windows from cygwin you need to add at the terminal prompt

setenv DISPLAY :0.0

(this allows programs such as nedit and xterm to open windows).

 

GFORTRAN (f90) instructions

http://www.neuralwiki.org/index.php?title=Installing_Fortran gives instructions for installing gfortran on a PC.  They link to this location (we have not checked this for viruses.

http://quatramaran.ens.fr/~coudert/gfortran/gfortran-windows.exe

 

If you have not used your PC for things other than web browsing, word, excel, power point and mail, you will probably have an easier time using the Athena system for the Fortran and C homework and activities.

You have several choices here.  The basic concept is to compile and run your code on an Athena machine and to create/edit your code either on Athena or your PC.

If you create your code on your PC using Wordpad, for example, then you need to be able to copy the code files from your PC to the Athena. The link below is to MIT software for the PC

http://ist.mit.edu/services/software/available-software?page=1&field_soft_app_type_value_many_to_one=All&field_platform_value_many_to_one=win&field_mit_status_value_many_to_one_1=All

The link to SecureCRT is

http://ist.mit.edu/services/software/securecrtfx/6x

SecureCRT allows you log into Athena machines remotely from your laptop and SecureFX allows you to transfer files between your PC and Athena and visa versa.  A quick start guide is

http://ist.mit.edu/services/software/securecrt/60x/quickstart-guide

SecureFX allows you to move files back and forth between your PC and Athena.  The quick start guide is

http://ist.mit.edu/services/software/securefx/60x/quickstart-guide

An alternative to using SecureCRT is use the Athena dialup ssh terminal. 

http://athena.dialup.mit.edu/ssh.html

This will create a window that looks like SecureCRT terminal window.  (You will still need SecureFX to moves files back and forth).

 

When you login into Athena with SecureCRT you will be connected to athena.dialup.mit.edu (the same connection when used the http connection above.   You can probably add the linerva.mit.edu server to SecureCRT and connect to this machine as well.  On athena you:

add gcc-4.0

gfortran loops.f -o loops

loops

./loops  # if the above does not work.

 

On athena.dialup.mit.edu, you can run gedit to edit your programs when using SecureCRT (I think: There may be an issue with X-windows forwarding.

On all systems you can use jedit remotely.  (This can be slow).

add jedit

jedit loops.f

 

For editing files, you can also edit on your laptop and use SecureFX to copy the files to athena.

Windows may want to add a .txt extent to your .f files because they are text files.  Once the files have been transferred to athena you use the mv to change the name (mv = move)

mv loops.f.txt loops.f

 

 

Intel Mac Instructions

Nedit can be downloaded from

http://sourceforge.net/projects/nedit/files/nedit-executable/5.5/nedit-5.5-MacOSX.tar.gz/download

gfortran downloaded from (see links with gfortran in name).

http://hpc.sourceforge.net/

(Fink commander is a great utility to install to get lots of linux packages for the Mac

http://finkcommander.sourceforge.net/

 

If you want to run fortan on athena then use terminal under Applications/Utilities or use X in from the same directory.  Once terminal runs use:

ssh -X <user name>@linerva.mit.edu

add gcc-4.0

gfortran loops.f –o loops

loops

 

You can use TextEdit on your Mac (or nedit when you run X, also under Applications/Utilities) to edit your files and

scp <filename> <user name>@linerva.mit.edu:

to copy files to athena.  If no folder information is given in file name, then scp needs to be run from the folder with the file.  (cd allows you change directory and pwd tells you which directory you are in.).

If you get a message, command not found when you try to run your program, e.g. loops, try

./loops

 

 

Other sources of information:

http://safari.oreilly.com O'Reilly series of books on programming (available with MIT certificate)

http://www.personal.psu.edu/faculty/h/d/hdk/fortran.html Useful link with lots of information on Fortran in its various forms.

 

Lecture 05: Continued with FORTRAN.  Character strings, Control statements if and do; other commands such as include, common, parameter.  More programs will be developed in class including simple output and computing root-mean-square scatter of randomly generated numbers.  Program developed in class: rms.f

Lec 05 PDF      Lec 05 PowerPoint    Thursday, September 23, 2010

 

Lecture 06: Finish up FORTRAN.  Compile, linking and runtime errors and miscellaneous topics.  Practice with using the language.

Lec 06 PDF      Lec 06 PowerPoint    Tuesday, September 28, 2010

 

Lecture 07: Examines the changes that were made in fortran90 with the introductions on more modern concepts in programming languages.

Lec 07 PDF      Lec 07 PowerPoint    Thursday, September 30, 2010

 

 

Lecture 08: Start of c-language programming. History, variables and executable statements. Additional links for this class

http://mitgcm.org/~cnh/12.010/2005/Lec08
http://cm.bell-labs.com/cm/cs/who/dmr/chist.html
Examples1.html
Examples2.html
Exercise.html

Lec 08 PDF      Lec 08 PowerPoint    Tuesday October 5, 2010

 

Lecture 09: Continuation of C. Covering Examined C-pointer; File Input/Output and the routines for formatted reads and write; Compiling C routines; The C preprocessor cpp; Structures in C; Memory management

Lec09_pnt.c is demonstration of pointers

Lec 09 PDF      Lec 09 PowerPoint    Thursday October 7, 2010

 

Lecture 10: Finish structures and memory management in C.  Start of C++. Inheritance and overloading in C++.

C and C++ routines used in class launch.c.

Ball.h and launch.cc

C++ folders ustring launch coord

Lec 10 PDF      Lec 10 PowerPoint    Thursday October 12, 2010

 

Lecture 11: Finish up of C++ looking at classes, inheritance and overloading.  We will look more carefully at the code linked in Lecture 10.  Homework number 3 has been set.

Lec 11 PDF      Lec 11 PowerPoint    Tuesday October 14, 2010

Example pieces of code for C and comparison to Fortran

C_Basics.html           C_Fortan_compare.html   C_Pointers.html

 

Lecture 12: Start of Mathematica.  These lectures are accompanied by a Mathematica Notebook that shows example of concepts presented in the notes

Lec 12 PDF      Lec 12 PowerPoint    Lec 12 NB       Tuesday October 19, 2010

Introductory screen casts from Wolfram

http://url.wolfram.com/oHLP0k/ Introduction (20 minutes)

http://url.wolfram.com/kY9~Ms/  Making models (15 minutes)

http://url.wolfram.com/omxeAw/  Use of the demonstrations site http://demonstrations.wolfram.com/index.html

 

Lecture 13: Continuation of Mathematica.  These lectures are accompanied by a Mathematica Notebook that shows example of concepts presented in the notes

Lec 13 PDF      Lec 13 PowerPoint    Lec 13 NB       Thursday October 21, 2010

 

Lecture 14: MATLAB: Introductory lecture on Matlab introducing system, variable types, control and functions.  The following Matlab M-files are used in the lecture: Lec01_01.m Lec01_02.m

Lec 14 PDF      Lec 14 Powerpoint    Tuesday October 26, 2010

 

Lecture 15: MATLAB: path command, variables, file IO and dialog boxes.  The following M-files are used Lec02_01_file.m Lec02_02_db.m Lec03_01_file.m (The last file will be used in the next lecture as well). A tar file with the data is Tseries.tar

Lec 15 PDF      Lec 15 Powerpoint    Thursday October 28, 2010

 

Lecture 16: MATLAB: Graphics handles and animation of figures.  The following M-files are used in class Lec03_movie.m and per_func.m

Lec 16 PDF      Lec 16 Powerpoint    Tuesday November 2, 2010

 

Lecture 17: MATLAB: Final class on GUI construction and use. A tar file with the data is Tseries.tar

Basic GUI layout: GPSanal.m gpsguio.m

Lec 17 PDF      Lec 17 Powerpoint    Thursday November 4, 2010

 

Lecture S1: Python  I

http://www.python.org

http://docs.python.org/index.html

http://docs.python.org/tutorial/

LecS1 PDF       Lec S1 PowerPoint    Tuesday November 9, 2010

 

Lecture S2: Python  

LecS2 PDF       Lec S2 PowerPoint    Tuesday November 16, 2010

 

 

Lecture 18: 3-D graphics in matlab.

Examples are: Lec18_3D.m                Lec18_TotalANC.avi           Lec18_RateANC.avi    Dif_1006_0407.fig    

Lec 18 PDF      Lec 18 Powerpoint    Thursday November 18, 2010

 

Lecture 18: Solution to differential equations in Mathematica and Matlab.

Mathematic notebook Lec19_NDsolve.nb

Matlab solutions are Lec19_ODE.m          Lec19_animate.m    Lec19_hit.m              Lec19_bacc.m

Lec 19 PDF      Lec 19 Powerpoint    Tuesday November 23, 2010

 

 

 

Lecture 23: Introduction of Class Project.  Examination of Q03 results. Graphics formats and issues about vector and pixel based graphics. Random number generators

http://gmt.soest.hawaii.edu/  GMT graphics package for mapping applications

The order of the class presentations will be decided in this class and posted after the class.

Matlab script to compare Q3 results Q3_compare.m

Data files matlab.dat fortrana.dat fortranb.dat C.dat mathematicf.dat

 

Lec 23 PDF      Lec 23 Powerpoint    Tuesday December 7, 2010

 

Homework Schedule for 2010

 

Homework will be set here and due on dates shown

Homework #1             PDF file          Due Thursday, September 30, 2010

 

Homework #2             PDF file          Q1_text.txt     Due Thursday, October 21, 2010

 

Homework #3             PDF file          Q1_text.txt     Due Thursday, November 04, 2010.

 

Homework #4             PDF file          Q1_text.txt     Due Thursday, November 18, 2010.

 

Project: Group pairs and project descriptions    Due Thursday, November 18, 2010.

 

Homework #5             PDF file          Q1_text.txt     Due Thursday, December 02, 2010.

 

 

Final Project    Demonstrated Thursday December 9, 2010.  Final are submissions due that day.

 

Each Presentation should take about 7-10 minutes, which includes a description of the project and a demonstration of the program.  The presentation, project description and program source code should be emailed to tah@mit.edu by Thursday December 09, 2010.

 

 

 


Project Presentation:  Thursday December 9, 2010

Project Presentation should be a total of 7-10 minutes long include (this is not very long):  Groups with two people will have 10-minutes and single person groups will have 10 minutes.  Some of the time should be left for questions.

1. Brief description of project

2. Role played by each member of team when more than one.

3. Demonstration of program.

 

All members of team should participate in the presentation.

 

Each project submission should include:

1.  Written document that outlines the algorithms used in the project.  The document should include:
Role of each person in the project
Methods that were used to verify that the code generated correct answers,

2.  Program design and layout discussion

3.  Program source code and instructions on installation

4.  Examples of output of program and instructions for using the program.

 

Final electronic submissions are due Thursday December 9,  2010.

 

Project Groups 12.010 2010

 

Time

Group

Topics

2:05

Susan Flowers

Sudoku solver (Mathematica)

2:13

Shaena Berlin,
Anna Merrifield

Predicting Run-up on the North Shore of O’ahu

 

2:24

Kirrah Jones,
Ciara Sivels

Neuton Diffusion

 

2:35

Benjamin Nield

Checkers Game

2:43

Martina Coccia,
Sedar Sahin

Expansion of Universe

 

2:54

Curran Oi

Tracking High-Energy Electrons

Break

 

 

3:15

Kimberly Huppert

Slope Stability analysis

3:23

Charles Hallam

Sudoku solver

3:31

Stephanie Sallum, Harriet Lau

Hangman

 

3:42

Lauren Jozwiak

Flexure models