Saving intermediate results The native file format for Mathematica expressions is the . M file. This is human readable text format, and you can view the file in a text editor if you ever doubt what is, or is not being saved.
You can load these files using Get The shorthand form for Get is: filename. M Using Get will replace or refresh any existing assignments that are explicitly made in the . M file Saving intermediate results that are simple assignments ( dat ) may be done with Put The shorthand form for Put is: dat >> "dat.
M This saves only the assigned expression itself; to restore the definition you must use: dat = Cell Properties > Initialization Cell on the cells that contain your function definitions. When you save the Notebook for the first time Mathematica will ask if you want to create an Auto Save Package. Do so, and Mathematica will generate a .
M file in parallel to the . Nb file, containing the contents of all Initialization Cells in the Notebook. Further, it will update this .
M file every time you save the Notebook, so you never need to manually update it Sine all Initialization Cells will be saved to the parallel . M file, I recommend using the Notebook only for the generation of this Package, and not also for the rest of your computations When managing functions, one must consider context Not all functions should be global at all times. A series of related functions should often be kept in its own context which can then be easily exposed to or removed from $ContextPath Further, a series of functions often rely on subfunctions that do not need to be called outside of the primary functions, therefore these subfunctions should not be global.
All of this relates to Package creation. Incidentally, it also relates to the formatting of code, because knowing that not all subfunctions must be exposed as global gives one the freedom to move many subfunctions to the "top level" of the code, that is, outside of Module or other scoping constructs, without conflicting with global symbols Package creation is a complex topic. You should familiarize yourself with Begin BeginPackage End and EndPackage to better understand it, but here is a simple framework to get you started.
You can follow it as a template for the time being This is an old definition I used before DeleteDuplicates existed: BeginPackage"UU`" UnsortedUnion::usage = "UnsortedUnion works like Union, but doesn't \ return a sorted list. \nThis function is considerably slower than \ Union though. " Begin"`Private`" UnsortedUnion = Block{f}, fy_ := (fy = Sequence; y); f /@ Join@## & End EndPackage Everything above goes in Initialization Cells.
You can insert Text cells, Sections, or even other input cells without harming the generated Package: only the contents of the Initialization Cells will be exported.
Saving intermediate results The native file format for Mathematica expressions is the . M file. This is human readable text format, and you can view the file in a text editor if you ever doubt what is, or is not being saved.
You can load these files using Get. The shorthand form for Get is: > "dat. M" This saves only the assigned expression itself; to restore the definition you must use: dat = Cell Properties > Initialization Cell on the cells that contain your function definitions.
When you save the Notebook for the first time, Mathematica will ask if you want to create an Auto Save Package. Do so, and Mathematica will generate a . M file in parallel to the .
Nb file, containing the contents of all Initialization Cells in the Notebook. Further, it will update this . M file every time you save the Notebook, so you never need to manually update it.
Sine all Initialization Cells will be saved to the parallel . M file, I recommend using the Notebook only for the generation of this Package, and not also for the rest of your computations. When managing functions, one must consider context.
Not all functions should be global at all times. A series of related functions should often be kept in its own context which can then be easily exposed to or removed from $ContextPath. Further, a series of functions often rely on subfunctions that do not need to be called outside of the primary functions, therefore these subfunctions should not be global.
All of this relates to Package creation. Incidentally, it also relates to the formatting of code, because knowing that not all subfunctions must be exposed as global gives one the freedom to move many subfunctions to the "top level" of the code, that is, outside of Module or other scoping constructs, without conflicting with global symbols. Package creation is a complex topic.
You should familiarize yourself with Begin, BeginPackage, End and EndPackage to better understand it, but here is a simple framework to get you started. You can follow it as a template for the time being. This is an old definition I used before DeleteDuplicates existed: BeginPackage"UU`" UnsortedUnion::usage = "UnsortedUnion works like Union, but doesn't \ return a sorted list.
\nThis function is considerably slower than \ Union though. " Begin"`Private`" UnsortedUnion = Block{f}, fy_ := (fy = Sequence; y); f /@ Join@## & End EndPackage Everything above goes in Initialization Cells. You can insert Text cells, Sections, or even other input cells without harming the generated Package: only the contents of the Initialization Cells will be exported.
BeginPackage defines the Context that your functions will belong to, and disables all non-System` definitions, preventing collisions. (There are ways to call other functions from your package, but that is better for another question). By convention, a ::usage message is defined for each function that it to be accessible outside the package itself.
This is not superfluous! While there are other methods, without this, you will not expose your function in the visible Context. Next, you Begin a context that is for the package alone, conventionally "`Private`".
After this point any symbols you define (that are not used outside of this Begin/End block) will not be exposed globally after the Package is loaded, and will therefore not collide with Global` symbols. After your function definition(s), you close the block with End. You may use as many Begin/End blocks as you like, and I typically use a separate one for each function, though it is not required.
Finally, close with EndPackage to restore the environment to what it was before using BeginPackage. After you save the Notebook and generate the . M package (let's say "mypackage.
M"), you can load it with Get.
Dr Wizard. ;) Thank You. – 500 Jun 14 at 3:35 @500 You're welcome.By the way, I did not answer point #3 directly, because I feel that once you are familiar with the tools available to you, organization will come naturally.
At least, that was my experience. – Mr.Wizard Jun 14 at 5:16 @Mr.Wizard: If you use PutAppend, is there a nice way to read a definition from somewhere in the middle of the file? – d00b Jun 14 at 16:45 @d00b that would depend on what you are using PutAppend for.
You say "definition" but I do not use Put for saving explicit definitions (meaning the . M file reads: x = {1, 2, 3}). Generally speaking, you can use ReadList, or Read and Skip.
– Mr.Wizard Jun 14 at 21:37 @500, as an added note, be careful of what your Private functions output as they can easily reveal the inner workings of your package. This is not to say, don't make packages, just you need to be more aware of good programming practices when using them. – rcollyer Jun 147 at 14:40.
Saving variable states: can be done using DumpSave, Save or Put. Read back using Get or.
1 For the "whether the weather" part – belisarius Jun 13 at 17:47 You wrote "Monolithic notebook containing everything. " Then I assume you ( have the luxury | face the burden ) of working alone. – nilo de roock Jun 13 at 22:24 @ndroock1 I don't usually work alone, but my Mathematica code is normally used by me only.
I've been doing experimental data processing, various calculations, concept demonstrations & visualizations, model studies etc. With notebooks typically not larger than say 10 pages. The largest I ever made had about 150 pages, and mixed experimental data processing & exploration with lots of graphs, model calculations, simulations and ideas. Gigantic, but manageable with foldable sections and just a single file to drag around if you want to show something.
– Sjoerd C. De Vries Jun 14 at 11:21 I'm right there with you on this one. While I'm the only one to see my notebooks, I tend to organize them very carefully so that I can find stuff in six months.
That, and actually thinking of them as actual notebooks with a bit more flexibility helps. (Lots of text cells for notes.) As for when I opt for a package + notebook vs notebook alone, rests on one question: do I need to reuse the material? If I do, usually discovered when I'm creating the second notebook, then I take the time to split out the needed code into a package.
– rcollyer Jun 15 at 14:31.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.