Introduction
to Programming for the Physical Sciences |
The course will cover basic programming skills using examples from
the
physical sciences. The course prerequisite is one semester of a
calculus-based
physics course such as Phys 141, 161 or 171, or credit on the physics
AP
exam. The language used is Python, which is an interpreted,
object-oriented
language with both scripting and systems level capabilities. The
course will use Python to provide instruction in the standard
programming techniques
used in upper-level languages. The course will include a strong
component
of visualization and graphing using the tools available
through
the VPython* implementation.
While this course satisfies the lower-level requirement in Computer
Sciences for Physical Sciences majors and Math majors, it is not a
substitute
for CMSC
106 (which uses the C language), and thus does not satisfy the
prerequisite for upper-level CMSC
courses. This course will provide a useful preparation for Phys
474 (Computational Physics) or Astr 415 (Computational Astrophysics),
although Python is not the language used in either of those
courses.
*The Visual library is Copyright (c) 2000 by David Scherer.
Instructor: Professor E. Williams (http://www.physics.umd.edu/spg/)
Room 2332 Physics,
Phone 301-405-6156
course web page: http://www.physics.umd.edu/courses/Phys165/williams2004/
e-mail: edw@physics.umd.edu (you must include "Phys 165
Fall 04" in subject line)
for help with class: phone, e-mail or see me after class to make
an appointment
Class Location:
M W F 3:00 PM, Room 1402 Physics
Approximately one day per week as announced, class will be moved to
Room 3115 Physics (POWL)
Course Software: Python 2.3 and VPython*
The software is installed and available for use in the Physics Open
Workstation Laboratory (POWL), room 3115 Physics Bldg. I strongly
recommend that you install a copy of the software on your personal
computer, so that you can work and maintain your own files
conveniently. The course software is available
as freeware at: http://www.vpython.org/download.html
If you follow the download instructions carefully you should have
no problem getting VPython up and running - just read all the
instructions before you start.
*The Visual library is Copyright (c) 2000 by David Scherer.
Textbook: Python Programming: An
Introduction to Computer Science, J. Zelle, Franklin, Beedle and Assoc.
2004
Required Downloads:
(additional required reference material will be indicated as needed in
the course)
1. Homework, 1 set per week, due Friday at or before the beginning of class.Grading
2. Programming Project: Due Monday Dec. 6, class presentations of projects Dec. 6-10.
3. Practical Exams: October 8, Nov. 19
4. Final Exam: Wednesday, Dec. 15, 1:30-3:30 PM
Homework: 30%Academic Honesty
Programming Project: 30%
Exams 40%
We will have class in the Workstation Lab (room 3115 Physics) most Fridays, and and on other dates to be announced as well. If you arrive in room 1402 and find no class there, go to 3115. Make sure you always bring PC-formatted floppy disks to the Lab (both for classes there and when you are working on assignments there) so that you can save your work. There are a large number of demonstration programs that are automatically included with the VPython download. These are on the server in the Workstation Lab. You are welcome to copy these to study and to edit them to create new programs.
The programming project and
most homework assignments will require creation of computer
programs.
You will submit these by e-mail. Send them to me at edw@umd.edu,
and you MUST include "Phys 165 Fall 04" in the subject line or
your e-mail will not end up where it needs to be for me to look at
it. If I can’t open the files you
send on the first try using Python, the grade for the assignment
will
be zero. So make
sure you've mastered e-mailing files: you should
test
this in advance by exchanging files with a friend. I will
NOT look at any files unless:
1) The subject line on the
e-mail is "Phys 165 Fall 04"
2) The listing of any
attached
program(s)
is pasted into the e-mail body as text.
3) The title of the file
is "<yourname><A#><P#>.py
For example "williamsA2P3.py" would be problem
three
from assignment two, handed in by Williams.
Successful programming requires logical thought and a lot of organization. You should organize the files you create on your disks with self-evident names in a logical structure of folders. Your python files can also be printed (for storage in your ring binder and easy reading) by copying the text from the IDLE window and pasting it into the editing/word processing program of your choice (e.g. bbEdit, Word…).
Programming solutions to the assignments will be posted on the Delphi network, which you can access from the POWL lab. The solutions (and occasional other miscellaneous information) will be on the drive "Course on Delphi\Groups(P:), in the folder P165.
Follow the systematic steps outlined in Zelle (see p. 45) for developing a program. Remember to include documentation, and to create a clear and professional looking output.
Programming Project
Programming Projec:
Due Monday, Dec. 6
Topic approval, no later than Monday, October 18
Approach approval no later than Monday, Nov. 1
Assignment: Choose a physical science problem that
involves
either multiple interacting objects, or stochastic processes, and write
a computer program to calculate the behavior of the system and display
the results effectively. Your program output should make it easy
for the user to understand your problem and the significance of the
result.
You should clearly indicate at least one independent variable in the
problem,
document the effects of changing the values for that variable in the
program
and explain the significance of the result.
As a required part of your project, you will describe and
demonstrate
your program in a 10 minute presentation for the class during the
final week of classes.
Program Specifications:
The program should illustrate your ability to do the following:
a) define and use functions
b) define and use classes and associated methods (use at least
one)
c) use multi-dimensional lists and nested loops (for many-body problem)
OR
Calculate statistical averages and distributions (for stochastic
problem)
d) create and use effective input/output screens, including
graphics
e) design, use and document test cases to insure the correct
functioning of your program
To do an interesting problem will probably require about 50-100 lines
of code* (documentation statements don’t count as lines of code).
The maximum length should not be more than 150 lines of code.
Programming Approach:
Use the 6 steps of software development :
1) Specify the problem requirements (and see me for topic
approval)
2) Analyze the problem
3) Design the algorithm (and see me for approach approval)
4) Implement the algorithm
5) Test and Verify
6) Document thoroughly and CLEARLY
*If you modify an exisiting demo or course program, you should
clearly
indicate with documentation statements what part of the code is
original
(e.g. you wrote it) and what parts of the code came from other sources.
Exam #1
Exam will be a practical programming exercise, held in the POWL lab.
Exam Rules:
Blank floppy disks will be provided.
Students may use any documentation or files on the course server.
Students may not use books, notes or any contents of their own floppy disk.
Exam Format:
Students will be asked to write a Python program that
a) reads in user-supplied initial conditions for a specified force problem
b) creates lists corresponding to time, position, speed and acceleration
c) fills the lists with values calculated using the Euler algorithm
d) performs a specified analysis on the lists
e) reports the results in a prescribed format
Sample Exam#1 Problem:
An object of mass m=1.50 kg is subject to a one-dimensional force F = -kx - bv, where k = 8.0N/m and b = 0.46 kg/s are positive constants. Write* a program that:
a) Prints a title and asks for input of the initial velocity vo and position xo.
b) Uses the Euler method to solve the equations of motion, and creates lists with the time, position, velocity and acceleration of the object. Solve the motion using a time interval of dt = 0.02*sqrt(k/m)/(2.0*pi). Run the solution until total time is t = 1000*dt.
c) Prints out a neat table (with a header) of t, x, v and a for every 50th time interval.
d) Sets up a conditional test loop to find the times in the calculated list (this will not be exact) when the position passes through a local maximum or a minimum Print out a neat table of the time and positions found.
*Suggestion: write and debug the program for part a) first. Then add part b, etc.
For examples of previous exams, see old web pages from Phys 165 in 2001 and 2003, at:
I will periodically make a
list
of the topics we have covered in class and assignments and post it
here.
Recommended reference documentation:
Topics Nov. 12 - Nov. 24
Conservation
of energy in Euler calculation
Error propagation
Screen interactions
Topics Oct. 22 - Nov. 12
Topics weeks of Oct. 11 - 22
Topics Sept. 27 - Oct. 8
Topics weeks of Sept. 24, Oct. 1
Topics week of Sept. 17
Topics week of Sept. 10:
Gravitation and
orbits
Introduction to "for" and "while" control structures
Topics week of Sept. 3:
|
Per Program |
Comments/documentation Title/name/date line in program Units documented in program Sections of code documented clearly a) relevance to problem b) explanation of code |
15 |
Good programming practice Numerical values defined as variables Self-evident variable names Indentation and spacing , logical structure Use of functions, lists, … Debugging points in program Expandable program structure |
15 |
Effective output: numbers include units, attention to significant figures column headers, column alignment graphical displays effective, labeled |
15 |
Program function Complete – has all required features Runs with correct results Well-organized (expandable) code |
55 |
Total Points | 100 |
Python files are compatible between Mac and PC. If you are moving files on a floppy disk, make sure it is PC formatted because otherwise you will not be able to use the disk on the PCs in the Physics OWL.
Copyright
(2004) University of Maryland, College Park. All rights reserved.
Permission to redistribute the contents without alteration is granted to educational institutionsfor non-profit administrative or educational purposes if proper credit is given to the University of Maryland, College Park as the source. |