Getting Started with Mathematica


This first Mathematica Tutorial will be provided as printed document or web page. Its purpose is to introduce you to the use of Mathematica documents – called notebooks. After this, we will present further tutorials as Mathematica notebooks

Go to a computer lab (ITC) and sit down at a computer to which you have access -- a Macintosh or Windows machine, or perhaps a Linux machine. Get someone to show you how to start the Mathematica program by double clicking on an icon, or, in Windows, by going through the Start menu on the lower left of the computer screen.

When Mathematica opens up, you see two or three Mathematica windows on the screen, one a large blank document window, one a grey “pallet” with various mathematical symbols on it, and possibly a welcome screen of some sort. Here we are only going to use the blank document window, so slide the other windows out of your way.

We are going to give the document window some better formatting features than it comes with to start with.

  1. Open the Window drop-down menu and choose “Show Toolbar”.
  2. Again on the Format menu, choose “Show Ruler”.
  3. On the Cell menu, choose “Cell Grouping” and then “Manual Grouping”.
  4. Near the top of the document click your mouse, and then hit the return key. A bracket will appear on the right and an open area for typing in the center of the page. Click with the mouse on the red bracket. Now look for a drop down menu near the top of your document (not at the very top of the computer screen), It will read “Input”. Click on the menu, and go up the menu to the choice “Title”. (You have just changed a Mathematica “Input Cell” into a “Title Cell”. Click somewhere to the left of the red bracket and type: “Mathematica Notebook Template”.

Your notebook now looks more or less like this. (I made these pictures with a previous version of Mathematica, so what you see will be slightly different, but similar in all essentials.)

You have just made a template notebook, which you are going to use as a template for your further work. In the Mathematica File menu, choose “Save As”, and then fill in the dialogue boxes to save your file with the name template.nb, for example on your desktop. (In the Windows operating system, use the name "template"; the file type (.nb) will be added automatically.)

You are going to need to use this template notebook in further sessions, so save it to a floppy disk, or a zip disk, or perhaps email it to yourself; in any case, put it somewhere where you can get to it and use it in future sessions.

Now open your template notebook, and immediately save a copy as notebook1.nb (use the File menu -> Save As mechanism as before.)

In your new notebook1.nb, change the title to “My first Mathematica Notebook” or something similar.

Just below the new title, click with the mouse and press the return key to open a new cell. Use the notebook’s drop down menu as before to change the type of the cell, this time to “Subsection”. Click somewhere to the left of the red bracket and type: “My first computation.” Now open yet another new cell below this cell, type 2 + 2, and hit enter (the rightmost enter key on a Mac or Windows keyboard) or shift+return (shift and return at the same time) to cause Mathematica to evaluate this expression. Out comes the answer 4 in a new cell, which is grouped with your 2+2 cell, like this.

If you didn’t get the output but only opened a new line in your input cell, you must have hit return instead of using the rightmost enter key or shift-return. The Mathematica program responds differently to the return key and to the enter key, or shift+return combination.

You can group the cells containing this impressive computation with the “subsection” cell just above as follows: Hold the mouse key down and slide the mouse cursor over the red brackets delineating the “subsection cell” and the computation cells. In this way you select the group of cells. Now with the mouse, select

Cell menu -> Cell Grouping -> Group Cells.

If you double click on the new group of cells, the computation cells disappear, leaving only the subsection cell as a title. Double click again and the whole group reappears.

At this point, your notebook1.nb looks like this:

Next, open up a new subsection cell, which you can label as “Factoring a polynomial”. Below this, in a new input cell, type the expression

Factor[x^3 – 125]

It is necessary to spell Factor with the initial capital and to use square brackets instead of any other type of parenthesis or brackets. Hit enter, and out pops the factorization. Group together your new subsection cell and the new computation cells.

Now your notebook looks like this:

Let’s put a couple more computations in our notebook before calling it a day.

For our third computation the label for the subsection could be “Plotting the graph of a function”, and the input for the computation will be:

Plot[Sin[x] E^x, {x, -2, 4}]

Again, it is necessary to use capital letters for Sin and E, and to use the two types of brackets exactly as shown.

After you are done, your notebook will look like this. (It wasn’t possible to get the whole notebook to be on the display at one time.

For our last computation, we are going to plot the graph of a surface. The title of our new subsection could be "Plotting a surface” and the input for the new computation is

Plot3D[Sin[x] Sin[y], {x, -2, 2}, {y, -2, 2}]

It is necessary to use capital letters, the two kinds of brackets, and commas exactly as shown. Group your subsection cell and the computation cells as before to make a fourth computation group.

Before displaying the result, let’s double click on our previous computation groups to make the details disappear, leaving only the titles of the groups. To make things pretty, let's also draw some horizontal lines between our computation groups, by choosing
Format menu -> Horizontal lines -> Paste Medium Line object.
Our notebook finally looks like this:

Save the result, and maybe print it out to show your friends and family. You now know how to enter and save computations in Mathematica.

In your future Mathematica work, please always open your template.nb as a starting point for your work; replace the title with something appropriate, and save the new notebook with an appropriate title, by choosing

File menu -> Save As.