How to save intermediate result of calculations in Mathematica

Sometimes, one needs to make long-time pleriminary calculations in Mathematica to obtain expressions for further work. It is not convenien to make them every time when notebook opens again.

An easy (but may be machine-dependent) way is to use DumpSave function. How it works. For example, we have a few variables for save:

a = (E^(-(r^2/(2 ell^2 w[z,t]^2))) (\[Psi]^\[Prime])[t])/ell^2
b = (E^(-(r^2/(2 ell^2 w[z,t]^2))) \[Mu][t] \[Psi][t] (w^(0,1))[z,t])/(ell^2 w[z,t] (1+(ell^2 w[z,t]^2)/r^2))

Now save them into the notebook directory:

DumpSave[NotebookDirectory[]<>"data.mx", {a, b}];

Now one can clear the definition and load saved variables:

Clear[a, b]
Get[NotebookDirectory[]<>"data.mx"]

Thanks to following links (see for additional information):

  1. http://mathematica.stackexchange.com/questions/4615/save-and-call-matrices-with-large-output-in-mathematica
  2. http://mathematica.stackexchange.com/questions/36/file-backed-lists-variables-for-handling-large-data
  3. http://mathematica.stackexchange.com/questions/1959/how-do-i-save-a-variable-or-function-definition-to-a-file

Leave a Reply