The reason this isn't working is that DumpSave
expects a symbol as the second argument. The doc page says:
DumpSave["file.mx",symbol] writes definitions associated with a symbol
to a file in internal Mathematica format.
With
ClearAll[y]
y[a_, b_, c_] := y[a, b, c] = NDSolve[{y''[x] == a x, y[0] == b, y'[0] == c}, y[x], {x, 0, 10}]
and
y[3/10, 2, 0]
{{y[x] -> InterpolatingFunction[][x]}}
you can see that y is a symbol
y // Head
Symbol
whereas y[3/10, 2, 0]
is not:
y[3/10, 2, 0] // Head
List
It is the expression {{y[x] -> InterpolatingFunction[][x]}}
as we have seen above.
To save expressions, such as a single instantiations of your memoized function, you can use Put
(>>
).
y[3/10, 2, 0] >> "test.mx"
Clear[y]
<<"test.mx"
{{y[x] -> InterpolatingFunction[][x]}}
To save the whole of y
, basic definition and all memoized versions, you can DumpSave
y itself:
DumpSave["test.mx", y];
Clear[y]
<<"test.mx"
?y
y[3/10,2,0]={{y[x]->InterpolatingFunction[{{0.,10.}},{4,23,2,{27},{4},0,0,0,0,Automatic},{{0.,0.0002208643237,<<...>>,9.481521054,10.}},{Developer`PackedArrayForm,{0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81},{2.,<<...>>,3.}},{Automatic}][x]}}
y[a_,b_,c_]:=y[a,b,c]=NDSolve[{(y^[Prime][Prime])[x]==a x,y[0]==b,(y^[Prime])[0]==c},y[x],{x,0,10}]
An extensive treatment of all ways to save data for posterity can be found here.
EDIT
To conveniently select a specific memoized definition you could use the following:
dumpSaveSelect[y_] :=
DynamicModule[{sol, file},
Manipulate[
(DownValues[y][[i, 1]]) /.
HoldPattern -> HoldForm, {{i, 1, "DownValue:"}, 1,
Length[DownValues[y]], 1, ControlType -> SetterBar},
Button["DumpSave",
sol = DownValues[y][[i, 1]];
file = SystemDialogInput["FileSave", "myfile.mx"];
DumpSave[file, sol],
Method -> "Queued"
],
ControlPlacement -> {Top, Bottom}
]
]
dumpSaveSelect[y]
