# Doing Computations in Notebooks

*Mathematica*notebook containing text, graphics, and

*Mathematica*expressions. The brackets on the right indicate the extent of each cell.

*Mathematica* notebooks are structured interactive documents that are organized into a sequence of *cells*. Each cell may contain text, graphics, sounds or *Mathematica* expressions in any combination. When a notebook is displayed on the screen, the extent of each cell is indicated by a bracket on the right.

The notebook front end for *Mathematica* provides many ways to enter and edit the material in a notebook. Some of these ways will be standard to whatever computer system or graphical interface you are using. Others are specific to *Mathematica*.

Doing a computation in a *Mathematica* notebook.

Once you have prepared the material in a cell, you can send it as input to the *Mathematica* kernel simply by pressing Shift+Enter. The kernel will send back whatever output is generated, and the front end will create new cells in your notebook to display this output. Note that if you have a numeric keypad on your keyboard, then you can use its Enter key as an alternative to Shift+Enter.

Most kinds of output that you get in *Mathematica* notebooks can readily be edited, just like input. Usually *Mathematica* will convert the output cell into an input cell when you first start editing it.

Once you have done the editing you want, you can typically just press Shift+Enter to send what you have created as input to the *Mathematica* kernel.

When you do computations in a *Mathematica* notebook, each line of input is typically labeled with In[n]:=, while each line of output is labeled with the corresponding Out[n]=.

There is no reason, however, that successive lines of input and output should necessarily appear one after the other in your notebook. Often, for example, you will want to go back to an earlier part of your notebook, and reevaluate some input you gave before.

It is important to realize that in most cases wherever a particular expression appears in your notebook, it is the line number given in In[n]:= or Out[n]= which determines when the expression was processed by the *Mathematica* kernel. Thus, for example, the fact that one expression may appear earlier than another in your notebook does not mean that it will have been evaluated first by the kernel. This will only be the case if it has a lower line number.

The exception to this rule is when an output contains the formatted results of a Dynamic or Manipulate function. Such outputs will reevaluate in the kernel on an as-needed basis long after the evaluation which initially created them. See "Dynamic Interactivity Language" for more information on this functionality.

As you type, *Mathematica* applies syntax coloring to your input using its knowledge of the structure of functions. The coloring highlights unmatched brackets and quotes, undefined global symbols, local variables in functions and various programming errors. You can ask why *Mathematica* colored your input by selecting it and using the Why the Coloring? item in the Help menu.

If you make a mistake and try to enter input that the *Mathematica* kernel does not understand, then the front end will produce a beep and emphasize any syntax errors in the input with color. In general, you will get a beep whenever something goes wrong in the front end. You can find out the origin of the beep using the Why the Beep? item in the Help menu.