Legacy Documentation

Mathematica® Teacher's Edition (2002)

This is documentation for an obsolete product.
Current products and services
 Documentation /  Mathematica Teacher's Edition /  The Teacher's Book /  Basic Calculations /  One Thing after Another /

3.2 Using Previous Results

In doing calculations, you will often need to use previous results that you have gotten. In Mathematica TE, % always stands for your last result.

Ways to refer to your previous results.

Here is the first result.

In[1]:= 77 ^ 2

Out[1]=

This adds 1 to the last result.

In[2]:= % + 1

Out[2]=

This uses both the last result, and the result before that.

In[3]:= 3 % + % ^ 2 + %%

Out[3]=

You will have noticed that all the input and output lines in Mathematica TE are numbered. You can use these numbers to refer to previous results.

This adds the results on lines 2 and 3 above.

In[4]:= %2 + %3

Out[4]=

Successive input and output lines need not appear in order since you can for example "scroll back" and insert your next calculation wherever you want in the notebook. You should realize that % is always defined to be the last result that Mathematica TE generated. This may or may not be the result that appears immediately above your present position in the notebook. With a notebook interface, the only way to tell when a particular result was generated is to look at the Out[n] label that it has. Because you can insert and delete anywhere in a notebook, the textual ordering of results in a notebook need have no relation to the order in which the results were generated.

Retrieving and reevaluating previous input and output.

You can always use Mathematica TE to retrieve or reevaluate previous input and output. In general, re-evaluating a particular piece of input or output may give you a different result than when you evaluated it in the first place. The reason is that in between you may have reset the values of variables that are used in that piece of input or output. If you ask for Out[n], then Mathematica TE will give you the final form of your n output. On the other hand, if you ask for In[n], then Mathematica TE will take the n input you gave, and reevaluate it using whatever current assignments you have given for variables.
In a standard session, Mathematica TE stores all your input and output lines for the duration of the session. In a very long session, this may take up a large amount of computer memory. You can nevertheless get rid of the input and output lines by explicitly clearing the values of In and Out, using Unprotect[In, Out], followed by Clear[In, Out].
An alternative strategy is to reset the line number counter $Line, so that new lines are numbered so as to overwrite previous ones.