Lab Notes

Math 213 -- Mathematics with Mathematica -- Fall 2009.
Christopher Hanusa -- chanusa@qc.cuny.edu -- Office: Kiely 409
On the web: http://qc.edu/~chanusa/courses/213/09_Fall/
File last modified: August 28, 2009

Working in the Math Lab

Please do not bring food or beverages into the laboratory!!!

Times at which the math lab is open are posted on the door to the lab.  These times are subject to change during the term.  You may also access Mathematica in some of the campus labs.

Opening Mathematica:

Simply click on Spikey on the dock at the bottom of the screen.  

If Spikey is missing, click on the magnifying glass in the top right corner and start to type Mathematica.  Once the program name appears under Applications, click it.

Getting Started:

If the Basic Math palette is not available, go to Palettes > Basic Math Assistant in the menu bar to open it.

Move the cursor.  When the I-beam is vertical, you can type in the cell you are hovering over.  When the I-beam is horizontal, clicking and typing creates a new cell in which to write. 

Use ENTER, not RETURN, to "enter" or "evaluate" an expression. [You may also use SHIFT-RETURN.]   The cursor does not have to be at the end of a line to enter the line.

For help with any command, use ?

? Plot

Save your work:

An Untitled document has not been saved. All your work will be lost if Mathematics crashes. Remember to save your work periodically.

When you are submitting your homework, make sure to save your homework worksheet with some sort of identifying information such as your last name or user name.

Printing:

Printing is discouraged for the most part to save paper.  You do not need to print out your homework; homework submission occurs through Blackboard.  In the case that you do wish to print a Mathematica-related worksheet, you may use the printer in the lab.  

Think a moment before you print a document. Do you really want to see everything in the document?  For example, Mathematica output can be many pages long!

If you are only interested in seeing one particular result, first select the cell or cells you are interested in using the bars on the right hand side and choose File > Print Selection.

If you are printing an entire document, remove unwanted cells first and suppress unnecessary output.  Make sure you have included comments for readability.

Several computers attempting to print at the same time can cause problems. If your document does not print, do not ask the computer to print again --- it is not the computer's problem.  Read the notes on printing posted by the printer.

Quitting:

First, save your document.  Then log off from your account. You do not need to close windows before quitting Mathematica. 

Watch the computer turn off just to be sure that you haven't left something that needs attention.

Crashes:

If the computer crashes, it can be restarted by pressing the command (the key with the apple), control, and power keys simultaneously.

If there seems to be a crash, but there are two small arrows in the upper left corner, then the problem is with the network. Often this occurs at start up and the quickest solution is to restart.

Comments:

You should be commenting your worksheets.  This means that you should not just type the commands that accomplish what you want, but that you should also narrate the reason for typing those commands.

You can add comments within an input cell by surrounding them with (* and *). 

For example, Mathematica will ignore "sets the initial value of i" in the line:

i = 1	(* sets the initial value of i *)

You can also create a text box by moving your horizontal I-beam to a position, clicking to fix this position, and typing COMMAND-7.

Cells:

Mathematica employs cells for all entries in a "Mathematica notebook."

When you type at the beginning of a new Mathematica document, you are in an input cell by default. If you want a different kind of cell, click on the cell bracket at the right to select the entire cell and select a particular style from Style under the Format menu. You can make this selection before you type anything. That is, before there is a cell bracket on the right.

If you select the cell and choose "Text", Mathematica sets the printing further to the left and pays no attention to what you type even if you press the enter key. Notice that the cell bracket for a text cell looks different from the bracket on either an input or an output cell.

After every evaluation, Mathematica is ready to create a new input cell just below the most recent output. Simply begin typing an a new input cell appears.

To place a new input cell between two cells, move the mouse until the cursor becomes a horizontal "I-beam" and click. A black line appears indicating that typing will create a new cell. 

To remove a cell, select the cell by clicking on the cell bracket and press COMMAND-X.

Suppressing output:

A semicolon may be used to suppress output. For example, when x=125 is entered, 125 appears in the output cell. Entering x = 125; tells Mathematica that x is 125 but the number does not appear in an output cell. This not only cleans up your output, but the semicolon can be used when constructing a large list that does not need to be displayed to be useful.

The semicolon can also be used to suppress the "graphics" cell that follows a graphic. Thus Plot[ ... ]; will produce only one cell containing the graph of ..., instead of two cells — the second simply containing the word "graphics."

Important Concepts:

All Mathematica functions begin with capital letters. It is good form to use capital letters when you define your own functions.  Use all lowercase letters to define a variable that is not a function.

Variables evaluated by a function are enclosed in [ ] not ( ).

Use return to add a new line to a cell. There is no need to put every input statement in a new cell.

Mathematica remembers what has happened during a session – the period of time between starting the program and quitting Mathematica. This means that care must be taken when using symbols that have been used earlier in a session – even when the symbol was used in a separate  Mathematica document.

If an expression you have defined gives a strange result, enter the expression alone and see what Mathematica thinks it is. For example, you may think f is a function but when you enter f, Mathematica returns 3. This shows that Mathematica is working with a different definition of f.

Mathematica knows nothing about what you want at the beginning of a session – even if you have just opened a document with many formulas. Expressions in a newly opened document must be entered before Mathematica knows about them.  To enter all commands present in a document, you can use the Evaluate > Evaluate Notebook command.

Typing the beginning of a function name and pressing COMMAND+K will list all the functions with that beginning. [If you like working from the keyboard, the arrow keys move up and down the list and return places the selected item in your document.]

Use a semicolon to suppress output [e.g., enter m=3; to tell Mathematica that m is 3 without expecting Mathematica to print 3 in the output.]