Homework

If you click below, the tutor will copy a file called ``ramp.txt'' into your
home directory. The file contains the code for the ``gravity'' and
``friction'' functions, as well as the ``distance'' and ``manyDistances''
procedures, that we discussed in this lesson.

As you do this homework, you will be modifying your copy of the file, and
eventually you will be handing it in. Every time that you click on the
button below, you will get a fresh copy of the file, and you'll lose any
modifications that you've made. So don't click on it more than once unless
you really want a fresh copy.

\check{Click here for a copy of ramp.txt}{$files/scripts/setup}{File copied
successfully}{File not copied}

We're going to ask you to make a series of modifications to the program. Since
you hardly know anything about Mathematica procedures, be sure to proceed carefully.
Be sure that each change that you make works before moving to the next. As you
go along, you'll probably learn just how picky Mathematica is about the format of a
program. But if you pay careful attention to the format of our program,
you should be able to make the modifications without too much pain.

(1) First of all, read the program into Emacs and take a look at it. You
will see that there are more comments than code. It is generally a good
idea to include lots of explanatory comments.

(2) Next, read the program into Mathematica and make sure that you can run it. To
read the program into Mathematica, pull down Mathematica's {\bf File} menu and choose the
{\bf Include ...}\ option. A small window will pop up. You should see
``ramp.txt'' in the ``Files'' list. Click on ``ramp.txt'', and then click on
the ``Read'' button, and the program will be read into Mathematica. Finally, go to
the Mathematica window and type the Enter key once so that everything that you just
read will be evaluated.

(3) Go back to your Emacs window and modify the program. Change it so that
instead of printing out the words ``seconds'' and ``meters'', it prints out the
letters ``s'' and ``m''. Save the changed program, and then read it into
Mathematica. Don't forget to use the Enter key to evaluate everything you've just
loaded. Make sure that the program works as modified.

(4) Again in your Emacs window, add a parameter to ``manyDistances'' so that
the user can specify the number of lines that the procedure should print
out. Right now, it prints out 10. Read the changed program into Mathematica and
make sure it works as modified.

(5) Back in your Emacs window, modify the program so that the user of
``manyDistances'' can specify the coefficient of friction between the block and
the ramp. This will require making small modifications to ``manyDistances,''
``distance,'' and ``friction.'' Note that in ``friction,'' the constant 1.0 is
the coefficient of friction. Read the changed program into Mathematica and make sure
it works as modified. (Small coefficients of friction mean small amounts of
friction, large coefficients of friction mean large amounts of friction.)

(6) Finally, back in your Emacs window, modify the program so that the user of
``manyDistances'' can specify the acceleration due to gravity. This will allow
the user to see how the block would move on the moon (where acceleration due to
gravity is 1.67 meters/sec/sec) or on Jupiter (22.9 meters/sec/sec) and not
just on Earth (9.8 meters/sec/sec). Read the changed program into Mathematica and
make sure it works as modified.

When you're done, submit your modified program for grading by doing

\begin{verbatim}
handin cai cs100 6 ramp.txt
\end{verbatim}