1
$\begingroup$

I am dealing with a problem that requires the use of both FindInstance and FindRoot nested in a non-trivial way. The result is dependent on some parameter value $t \in [0,1)$, therefore I use

sol[t_]:=FindRoot[...]

For each t, the calculation of the result takes about 2 minutes (for some values of t it's faster, for others slower), resulting in

Plot[sol[t], {t,0,1}]

to take several hours. As I want to do further calculations/plots with $sol$, I learned from a previous question that i can "save" the results obtained by using

sol[t_]:=sol[t]=FindRoot[...]

However, this still requires me to redo the calculations every time I start Mathematica or the kernel dies for some unexpected reason.

Is there a way to save/export the results obtained "within" $sol$, such that I can "load" them at the beginning of a session? (I apologize for the vague terms, please let me know if I need to clearify my question).

$\endgroup$
6
  • $\begingroup$ Have a look at DumpSave. $\endgroup$ Feb 18, 2013 at 8:40
  • $\begingroup$ Related: mathematica.stackexchange.com/q/1959/131 and mathematica.stackexchange.com/q/5450/131 $\endgroup$
    – Yves Klett
    Feb 18, 2013 at 8:41
  • $\begingroup$ Thanks to you both, that's exactly what I was looking for. I guess I should have found this myself, but I was apparently not looking with the right search phrase. $\endgroup$
    – Mitch D
    Feb 18, 2013 at 8:58
  • $\begingroup$ You are welcome. If your question is not found to be a duplicate, it will be useful if you write an answer yourself once you have found the right solution to help others benefit from your insights. $\endgroup$
    – Yves Klett
    Feb 18, 2013 at 9:01
  • $\begingroup$ Changing your user name to something more individual should also help the overall look of the site and facilitate interaction. $\endgroup$
    – Yves Klett
    Feb 18, 2013 at 9:03

1 Answer 1

1
$\begingroup$

As b.gatessucks and Yves Klett pointed out, 'DumpSave' is the solution. Taking what was written at How do I save a variable or function definition to a file? one can use

DumpSave["~/Desktop/solt.mx", sol]

to save and

DumpGet["~/Desktop/solt.mx"]

to load the results that where calculated while plotting the function $sol$.

Furthermore, as described at How to save all data in all variables so that loading it is fast? (and also the Documentation of DumpSave), by using

DumpSave["~/Desktop/dumpall.mx", "Global`"]

the results and definitions of all symbols/functions are saved and can later be loaded using DumpGet.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.