Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Saving Interpolated Function

374 views
Skip to first unread message

led...@ssb.rochester.edu

unread,
Sep 7, 2007, 2:03:22 AM9/7/07
to
I am doing some numerical analysis leading to an interpolated function
that I will need later.

These calculations take many minutes, and I want to beable to save the
interpolated function--so it does not have to be regenerated every
time I come back to the problem.

How can I do this.?

Thanks


Phil


sashap

unread,
Sep 8, 2007, 3:49:03 AM9/8/07
to
Hi Phil,

You need to use Import/Export.

Using v 6:

(* construct an interpolating function *)
In[1]:= if =
y /. NDSolve[ {y''[t] - y[t] t^2 == 0, y[0] == 0, y'[0] == 1},
y, {t, 0, 10}][[1]];

In[2]:= Head[if]

Out[2]= InterpolatingFunction

In[3]:= Export[
ToFileName[{$HomeDirectory, "Desktop"}, "interfunc.m"], if]

Out[3]= C:\Documents and Settings\....\Desktop\interfunc.m

In[4]:= if2 =
Import[ToFileName[{$HomeDirectory, "Desktop"}, "interfunc.m"]];

In[5]:= if2 === if

Out[5]= True

Oleksandr Pavlyk
Wolfram Research

On Sep 7, 1:03 am, "lede...@ssb.rochester.edu"

Jean-Marc Gulliet

unread,
Sep 8, 2007, 3:53:05 AM9/8/07
to
led...@ssb.rochester.edu wrote:

The function *DumpSave* should be what you are looking for. Here is an
example: we save the interpolating function in the default user
directory, then, in a new session, we load its definition with *Get* (or
<<).

In[1]:= f =
First[u /. NDSolve[{u''[t] + u[t] == 0, u[0] == 0, u'[0] == 1},
u, {t, 0, \[Pi]}]]

Out[1]= InterpolatingFunction[]

In[2]:= DumpSave["f.mx", f]

Out[2]= InterpolatingFunction[]

In[3]:= Quit[]

(* Later, in a fresh session *)

In[1]:= << f.mx

In[2]:= Plot[{f[t], f'[t]}, {t, 0, \[Pi]}]

[... graphic deleted ...]

Regards,
--
Jean-Marc

Sseziwa Mukasa

unread,
Sep 8, 2007, 3:55:06 AM9/8/07
to

On Sep 7, 2007, at 2:03 AM, led...@ssb.rochester.edu wrote:

> I am doing some numerical analysis leading to an interpolated function
> that I will need later.
>
> These calculations take many minutes, and I want to beable to save the
> interpolated function--so it does not have to be regenerated every
> time I come back to the problem.
>
> How can I do this.?

Use Get and Put eg:

g=Interpolation[Range[5]];
g>>"func";
e=<<"func";
Plot[g[x],{x,1,5}]
Plot[e[x],{x,1,5}]

Regards,

Ssezi

Jens-Peer Kuska

unread,
Sep 9, 2007, 6:24:23 AM9/9/07
to
Hi,

Put[] it into an *.m file

Regards
Jens

roby....@gmail.com

unread,
Sep 9, 2007, 6:25:24 AM9/9/07
to
f = Interpolation[{1, 2, 3, 4}];
Save["test", f]


Get["test"]


regards robert


0 new messages