RE: Notebook question
- To: mathgroup at smc.vnet.net
- Subject: [mg35884] RE: [mg35871] Notebook question
- From: "David Park" <djmp at earthlink.net>
- Date: Mon, 5 Aug 2002 06:01:58 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Tom, Basically, if you want to open a notebook and evaluate some cell in the notebook, then every cell that loads a package, creates or contributes to a definition or calculates a quantity used by that cell must be evaluated first. No other cells need to be evaluated. So this raises the question of how to organize a notebook that will be easy to come back to, or easy for others to look at. This is how I do it. It is not the only way, and it may not be the best way, but it works for me. First, learn how to use Cell grouping (Sections, Subsections, Subsubsections), and how to open and close Cell groups. Stay with the default AutomaticGrouping. It has a few minor weak points but basically everybody knows how it works and it does the job. I put all of the initialization statements at the top of the notebook. These are generally Needs statements to load any needed packages. You might also want statements to turn off the spelling warning messages. If there are a lot of general initialization statements I put them into a Section called Initialization. I make these cells Initialization cells. When you first save the notebook, Mathematica will ask if you want to create an AutoSavePackage. Answer No. The next time you load the notebook and try to evaluate ANY Input cell, Mathematica will automatically ask if you want to evaluate the initialization cells. Answer Yes. I then create a Section called Routines. It is initially empty. However, as I work on the material I often find that I have to develop little routines that do various subcalculations. Once I have such a routine perfected (sic!) I move it to the Routines Section and make it an Initialization cell. (It is also a good practice to write usage statements for these routines. Later, it will help you and others understand what the routines do and how to use them. Also, if you create a collection of nifty routines, you are not far from turning them into a package.) Suppose I am working on some topic, say Topic1. I will create a Topic1 Section and then try to work it out. Often my first attempts don't work very well, so I will change the Section head to Topic1 - First Try, copy it and try again. When I get it worked out, I will delete all of the initial attempts, and move any routines I developed to the Routines Section. You can then turn the remaining Topic1 Section into a nice exposition section where you actually do the calculation you want in a clear and clean manner. If you come back to the notebook later, you can go directly to the Topic1 section and start evaluating the first cell. All of the Initialization cells needed will automatically be evaluated. David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Thomas J. Fararo [mailto:tjf2+ at pitt.edu] To: mathgroup at smc.vnet.net Hello, I am still relatively new to Mathematica so please take this into account in reacting to this perhaps simple question. Namely, suppose I have written some code in a given notebook, saved it, and then exited in and closed Matheamtica.Later I restart Mathematica and open the same notebook. Am I supposed to take some particular step before continuing my work? To be concrete, suppose I have a Do loop with some parameter p that previously I had set at p = 10 and now (in restarting) I want to return to the Do loop and replace the 10 with another number, and then evaluate the cell, e.g., to display a bar chart for a list determined by the new value. My experience, as limited as it is, is that this doesn't work unless I go up to the top of that notebook and re-evaluate all the cells leading up to the Do loop. Yet, it is doubtful that this is what experienced Mathematica users do -- so what steps should one take in order to have total continuity from day 1 to day 2, say, in developing and evaluating code in a given notebook? Thanks very much for any help. Tom