0
$\begingroup$

I have a lot of interpolated functions that I have generated from a numerical integral. It takes me 2 hours or so to generate them so I would prefer to save and import them.

I have tried Export[...] and DumpSave[...]. DumpSave[...] works for a single Interpolation[...] ut not for a table of them.

Does anyone have a suggestion on how to export a table of interpolated functions?

$\endgroup$
3
  • 1
    $\begingroup$ ` DumpSave[…,{ip1,ip2,...}]` works for a list of interpolation functions too! $\endgroup$ Jul 30, 2020 at 8:12
  • $\begingroup$ Hmm...I better check my code, thanks! $\endgroup$
    – user27119
    Jul 30, 2020 at 8:24
  • $\begingroup$ @UlrichNeumann How can I actually use the functions? I think I was able to use DumpSave as you suggest, but when I import it with Get I can't figure out a way to use it. Could you provide some guidance? $\endgroup$
    – user27119
    Jul 30, 2020 at 16:53

1 Answer 1

1
$\begingroup$

guidance to your comment:

define some user functions sin,cos

data

= Table[{x, Sin[x], Cos[x]}, {x, Subdivide[0, 2 Pi, 50]}]; sin = Interpolation[data[[All, {1, 2}]]]; cos = Interpolation[data[[All, {1, 3}]]];

save the functions

DumpSave["sincos.mx", {sin, cos}]

Clear[sin,cos] (* new session*)

load function

Get["sincos.mx"]

now the loaded functions are available

Plot[{sin[x], cos[x]}, {x, 0, 2 Pi}]

That's it!

enter image description here

$\endgroup$
3
  • $\begingroup$ Thanks for posting this, especially as strictly speaking it's out of the original question scope. If I want to pick the i'th object when using Get is that possible, so in your example say I only want to deal with/use sin. $\endgroup$
    – user27119
    Jul 31, 2020 at 8:13
  • $\begingroup$ @Q.P. Ulrich’s answer seems to be exactly what you are looking for. If you’re keen on Importing only one element from the list which you’ve dumpsaved, that is seemingly a different question dealing with different functionality & goals etc than what you posed. If you only want to use one function from your DumpSave, in your example of wanting only sin, you would call only sin, then. Perhaps you may DumpSave a list, say trigfuncs={sin, cos} for example, then call this by trigfuncs[[i]] where i=1 for sin, but this is seemingly less functionality. $\endgroup$ Jul 31, 2020 at 8:40
  • 1
    $\begingroup$ @CATrevillian Thanks for your helpful hint. Additional one could useNames["Global*"]` (before and after Get) to get the list of dumpsaved functions. $\endgroup$ Jul 31, 2020 at 8:46

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.