2
|
4196 Views
|
4 Replies
|
4 Total Likes
View groups...
Share
GROUPS:

# Is there a way to store the InterpolatingFunction object in a file?

Posted 11 years ago
 My question is that if we can place the InterpolatingFunction object into a file so I can use it directly next time even if I have quit kernel? For instance, I solve this function numerically, s = NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}]{{y->InterpolatingFunction[{{0.,30.}},"<>"]}}Can I call the result of "y" without recompute differential equation? Of course I can export point value of y to some file and save it later. I am looking forward to a neater way to handle this . Any idea is appreciated.
4 Replies
Sort By:
Posted 11 years ago
 Beware!The internal structure of InterpolatingFunction statements is not documented and may not be consistent between versions of Mathematica. That is, it not always possible to use an InterpolationFunction expression created in one version of Mathematica inside another version.
Posted 11 years ago
 @Sean, this is true. I know that the .mx build is ususually not supported among different versions.
Posted 11 years ago
 Great! they work well!
Posted 11 years ago
 1) Simplest saving to a files = NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}];Export["test.m", s];Saving to .m format will completely preserve the information. Importing it back will work as original one:saved = Import["test.m"]Plot[Evaluate[y[x] /. saved], {x, 0, 30}, PlotRange -> All]2) Saving in the notebookYou can export to a compressed string via Compress and save that string in the notebook. Then Uncompress will give you the original result.3) More extensive discussionHow do I save a variable or function definition to a file?
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.