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:
For 2009 class, class
number and date will change as this years versions of the notes are added.
New classes are shaded.
|
Class |
Date |
Instr. |
Topic |
|
1 |
09/10 |
TH |
Introduction: Problem
formulation, algorithm development, algorithm implementation, and algorithm
verification. Structure and documentation |
|
2 |
09/15 |
CH |
|
|
3 |
09/17 |
TH |
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/22 |
TH |
|
|
5 |
09/24 |
TH |
|
|
6 |
09/29 |
TH |
|
|
7 |
10/01 |
TH |
|
|
8 |
10/06 |
CH |
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/08 |
CH |
|
|
10 |
10/15 |
CH |
|
|
11 |
10/20 |
CH |
|
|
|
|
|
|
|
12 |
10/22 |
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/27 |
TH |
|
|
14 |
10/29 |
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 |
11/03 |
TH |
|
|
16 |
11/05 |
TH |
|
|
16.2 |
11/10 |
SM |
Python scripting
language program |
|
16.4 |
11/12 |
SM |
|
|
17 |
11/17 |
TH |
Finish up Matlab GUI
programming and applications |
|
17s |
11/19 |
CH |
|
|
18 |
11/24 |
TH |
Ordinary differential
equation (ODE) solutions used Matlab and Mathematica |
|
19 |
12/01 |
TH |
Advanced graphics in
Matlab, 3-D representation and exportable animations. |
|
20 |
12/01 |
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. |
|
21 |
12/03 |
CH |
|
|
22 |
12/08 |
CH |
|
|
|
|
|
This material not
covered. Graphics: Review of common graphics program. Graphics with spreadsheets,
Kaleidagraph, Generic Mapping Tool (GMT). Numerical Methods: Introduction to
numerical methods. Statistical analysis
tools including generation random variables and correlated random numbers. |
|
|
12/10 |
All |
Final Project
Presentations |
Instructors: TH: T.
Herring tah@mit.edu,; CH Chris Hill cnh@plume@mit.edu
![]()
|
The lecture notes are
converted from Microsoft Power Point documents to web pages and portable
document format (PDF). The most
complete version of the documents is the power point files, which we make
available for each lecture. The
HTML version will depend on the browser and OS on which the pages are
viewed. Lecture notes are added
as the class is taught. |
|
Lecture 01: Class introduction; overview of languages;
Program development |
|
Web Page
Lec 01 PDF Lec01 Power Point Thursday, September 10, 2009 |
|
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 and at the bottom of the
web pages (These notes are often important for doing the homework and are not
in the PDF file). |
|
Web Page Lec 02 PDF Lec 02 Power Point Tuesday, September 15, 2009 |
|
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 Minor links for those interested. |
|
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
|
|
Web Page Lec 03 PDF Lec 03 PowerPoint Thursday, September 17, 2009 |
|
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. |
|
Web Page Lec 04 PDF Lec 04 PowerPoint Tuesday, September 22, 2009 |
|
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 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 https://wserv.mit.edu/fcgi-bin/softcount?product=mit/win/mit-xwin32-9.1.msi 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). 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 One the second page, SecureCRT and SecureFX can be downloaded
and installed. 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). On these machine,
gfortran does not run correctly (missing shared library) and so you should
use: add gcc-3.4 g77 loops.f -o loops loops (The last line runs the program. If you get a command not found message try ./loops You can probably add the linerva.mit.edu
server to SecureCRT and connect to this machine. On linerva gfortran does run and you can: 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). (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 |
|
Web Page Lec 05 PDF Lec 05 PowerPoint Thursday, September 24, 2009 |
|
Lecture 06: Finish up FORTRAN. Compile, linking and runtime errors and miscellaneous
topics. Practice with using the
language. |
|
Web Page Lec 06 PDF Lec 06 PowerPoint Tuesday, September 29, 2009 |
|
Lecture 07: Examines the changes that were made in fortran90
with the introductions on more modern concepts in programming languages.. |
|
Web Page Lec 07 PDF Lec 07 PowerPoint Thursday, October 01, 2009 |
|
|
|
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
|
|
Web Page Lec 08 PDF Lec 08 PowerPoint Tuesday October 6, 2009 |
|
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 |
|
Web Page Lec 09 PDF Lec 09 PowerPoint Thursday October 8, 2009 |
|
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. |
|
Web Page Lec 10 PDF Lec 10 PowerPoint Thursday October 15, 2009 |
|
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. |
|
Web Page Lec 11 PDF Lec 11 PowerPoint Tuesday October 20, 2009 Example
pieces of code for C and comparison to Fortran |
|
Lecture 12: Start of Mathematica. These lectures are accompanied by a Mathematica Notebook
that shows example of concepts presented in the notes |
|
Web Page Lec 12 PDF Lec 12 PowerPoint Lec 12 NB Tuesday
October 22, 2009 |
Introductory screen casts
from Wolfram
http://url.wolfram.com/oHLP0k/
Introduction
http://url.wolfram.com/kY9~Ms/ Making models
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 |
|
Web Page Lec 13 PDF Lec 13 PowerPoint Lec 13 NB Thursday
October 27, 2009 |
|
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 |
|
Web Page Lec 14 PDF Lec 14 Powerpoint Thursday October 29, 2009 |
|
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).
The data for these M-files can be found in MatData. A tar file with the data is TSeries.tar |
|
Web Page Lec 15 PDF Lec 15 Powerpoint Tuesday November 3, 2009 |
|
Lecture 16: MATLAB: Graphics handles and animation of
figures. The following M-files
are used in class Lec03_movie.m and Matlab/per_func.m |
|
Web Page Lec 16 PDF Lec 16 Powerpoint Thursday November 5, 2009 |
|
Lecture S1: Python |
|
Web Page LecS1 PDF Lec S1 PowerPoint Tuesday November
10, 2009 |
|
Lecture S2: Python |
|
Web Page LecS2 PDF Lec S2 PowerPoint Thursday
November 12, 2009 |
|
Lecture 17: MATLAB: Final class on GUI construction and
use. The following M-files are
used (along with the data from MatData: A tar file with
the data is TSeries.tar |
|
Web Page Lec 17 PDF Lec 17 Powerpoint Tuesday November 17. 2009 |
|
|
|
Lecture 18: Solution to differential equations in
Mathematica and Matlab. |
|
Mathematic notebook 12.010.Lec18_NDsolve.nb Matlab
solutions are Lec18_ODE.m Lec18_animate.m Lec18_hit.m
Lec18_bacc.m |
|
Web Page Lec 18 PDF Lec 18 Powerpoint Tuesday November 24, 2009 |
|
Lecture 19: 3-D graphics in matlab. |
|
Examples are: Lec19_3D.m Lec19_TotalANC.avi Lec19_RateANC.avi Dif_1006_0407.fig |
|
Web Page Lec 19 PDF Lec 19 Powerpoint Tuesday December 1, 2009 |
|
Lecture 22: Introduction of Class Project. Graphics formats and issues about
vector and pixel based graphics. http://gmt.soest.hawaii.edu/ GMT graphics package for mapping
applications |
|
Web Page Lec 22 PDF Lec 22 Powerpoint Tuesday December 2, 2008 |
|
Lecture 23: Class projects: Graphics Processor Unit (GPU)
processing. Statistics and random number generators. M-file randtest.m is implementation of an LCG random number
generator. The order of the class presentations will be
decided in this class and posted after the class. http://www.nvidia.com/object/cuda_get.html
http://www.accelereyes.com/ -- Matlab
implementation |
|
Web Page Lec 23 PDF Lec 23 Powerpoint Thursday December 4, 2008 |
![]()
Homework Schedule for 2009 (replaced during
semester with new ones)
Homework will be set here
and due on dates shown
Homework #1 Web Version PDF file Due Thursday, October
1, 2009
Solution PDF file
Homework #2 Web version PDF file Due Thursday, October
22, 2009
Solution PDF
file HW02_01.f HW02_02.f HW02_03.f DPend.h
Homework #3 Web Version PDF Due Thursday, November
05, 2009.
Solution PDF file HW03_01.c HW03_02.c HW03_03.c DPendC.h
Homework #4 Web Version PDF Due Thursday, November
19, 2009.
Solution PDF file 12.010_HW04_09.nb
Project: Group pairs and project
descriptions Due Thursday,
November 19, 2009.
Homework #5 Web Version PDF Due Thursday, December
03, 2009.
Final Project
Demonstrated Thursday December 12, 2009.
Final are submissions due that day.
|
Each
Presentation should take about 15 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
Wednesday December 11, 2009. |
![]()
Project Groups 12.010 2008
|
2:05-2:20 |
Amanda Levy |
Solar Subtense Program |
|
2:20-2:35 |
Stefan Gimmillaro |
The Sodoku Master: |
|
2:35-2:50 |
Eric Quintero |
Encryption/decryption algorithm |
|
2:50-305 |
Karen Sun and Javier Ordonez |
Truss Collapse Mechanism |
|
3:15-3:30 |
Melissa Tanner and Sean Wahl |
Phase diagram generator for binary and ternary
solid-state solutions |
|
3:30-3:45 |
Adrian Melia |
Model of an accelerating universe |
Project Presentation
should be a total of 15 minutes long include:
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 Wednesday December 10. 2008.
abn