MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Basic Question about Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83396] Re: Basic Question about Mathematica
  • From: Thomas E Burton <tburton at brahea.com>
  • Date: Mon, 19 Nov 2007 06:17:36 -0500 (EST)

> I only started using Mathematica yesterday, so please excuse this  
> very newbie question.


In version 5.x and prior, I would direct to you Chapter 1 of the The  
Mathematica Book (in print and on line). In version 6, the following  
two tutorials may suffice (type the following two search strings into  
the Doc Center's search box)

tutorial/MathematicaSessions
tutorial/UsingPreviousResults   [note especially the last paragraph]

> ... Being new, I keep making a lot of mistakes while experimenting,  
> and each time when I realize the mistake, I delete the cell and  
> start over again. When I do this, Mathematica does not continue to  
> number the "In[n]" and "Out[n]" lines sequentially based on what is  
> actually on the notebook, but instead remembers the numbers from  
> the deleted cells even after I have deleted them.
>
> Consequently, with only 10 or so cells on my notebook, I have  
> numbers like "In[102]" because Mathematica is remembering all the  
> deletions, and all the times I asked it to recalculate.


Computations are performed and remembered in a background process  
called the kernel. In and Out record chronological kernel activity.   
The kernel's attention jumps from input-cell to input-cell in the  
order in which you execute them. It's natural and common to execute  
down the page, and menu command "Evaluation/Evaluate Notebook" will  
execute the entire notebook top to bottom,  but you can execute cells  
in any order. Indeed, when I spot a mistake in a cell, I don't delete  
it; rather, I edit it and reexecute it on the spot, out of spacial  
order, to see if my correction works. Dependence upon previous  
results may disallow this short-cut, but I try.

Out[] saves corresponding results, Out[n] immediately below In[m].  
Often n>m because one input cell generated two or more output cells.

> What is worse is that it seems to remember errors and variables  
> from the deleted cells. If I previously made a mistake with some  
> variable or expression and deleted it, then tried to define it  
> again, it gives me the same error I got before I deleted it.


The kernel's memory is not limited to what you see in the notebook.  
"Clear" symbols as needed.

> Clearing the history does not help.


As you'll see from the tutorials, the kernel remembers all output  
cells in terms of their sequence number n. Results are accessible by  
Out[n] and variations. You can disable this memory by setting  
$HistoryLength=0.  Also, you may assign results to symbols. Use Clear  
to erase those.

> Is there any way to get Mathematica to totally forget stuff that I  
> have deleted and only evaluate whatever is in the notebook at a  
> given time?


Menu:
(1) Evaluation/Quit Kernel ..
(2) Evaluation/Evaluate Notebook

> It would also be great if it could renumber the "In[n]" and "Out 
> [n]" statements so they bear some semblance to the actual number of  
> cells in my notebook.


See the previous response, but when you execute cells out of spacial  
order or work simultaneously in two or more notebooks sharing a  
kernel, you'll appreciate the way In and Out work. Finally, at any  
time you can set

$Line = x

to force In and Out to increment from x.  I've never profited from  
doing so.


  • Prev by Date: Re: Tally[ ] and Union[ ]
  • Next by Date: Re: Mathematica question : Stepsize control
  • Previous by thread: Re: Basic Question about Mathematica
  • Next by thread: Physical Simulations with DSolve