You are expected to have some experience with programming prior to this course, as many of the homework assignments will include implementing an algorithm. The programs you write will not be fancy, but they will require that you be comfortable writing and debugging programs of perhaps two to three pages in length. The types of programming features you should know are:
- How to read input from the user and write output to the user
- How to perform loops and conditional statements
- How to declare and call subroutines
- How to specify and use an array (i.e. a subscripted variable)
- How to write recursive function calls
The programs we write will not require complicated programming statements; the sophistication comes from the algorithms that we will implement, not the language features you will be using.
You are allowed to use whatever language you like, with the following caveats:
- My preferred languages are:
- Python, Php, Ruby, TCL/TK, or some other interpretted language
- My second choices are:
- C or Pascal
- FORTRAN (if you really are into numerical programming)
- Mathematica, Maple, MatLab (if you have no other choice)
Some of you may wish to use Mathematica or some other computer algebra system to write your code. That is OK, although some assignments might be subtler in those languages. I do not have ready access to Maple or MatLab, so I would prefer you not use these as your programming language if it can be avoided.
When you turn in a programming assignment, you should include the following:
It is a good idea for your program to print out the values that were input (in which case, you can give me just the output). For example, if your program prompts for the coefficients of a polynomial and a value for a tolerance variable called "epsilon", and uses these to find an x-value where the polynomial is within epsilon of zero, your output might look like:
- A written summary of the main points of your program. That is, describe the basic structure of what your program does, and any important aspects of your implementation of the algorithms. You don't have to explain the details that we have already worked out in class, but should say how you have organized your program to handle the algorithms. If your assignment was to modify an algorithm from class, you should explain the important new ideas that you have included, and the changes that you have made. These is not supposed to be comments within your code, but a separate written description.
- Enough comments within your code to make it clear what is happening. For instance, if you use global variables, you should say what they are for. (It is a good idea to name them appropriately, too; for example, if you are writing a program that uses polynomials, it is better to have an array named "coefficients" than one named "a".) Each subroutine should be described briefly (and named appropriately), and you should point out any subtle ideas that it might include.
- A printout of the final, working version of the program.
- A printout of the input that you need to supply for your program to run.
- A printout of the output produced by your program for the input you have supplied.
Polynomial: 1 x^2 + -2 x + -5 Root: x = 3.449 (for an epsilon of .005)
If you are running on a Unix machine, you can capture the output of your program into a file using "redirection". For example, if your program is called
hw1, then the command
hw1 > hw1.txt
will capture the output of your program into a file called
hw1.txt. Otherwise, you might need to cut and past the output into a text document by hand.
You can also store the input in a file and not have to retype it every time you run your program. For example
hw1 < hw1.in > hw1.txt
read the input from
hw1.inand stores the results in
You may be able to get a file that includes both the input and the output by using the script command (see the man page for more details).