Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: using Save/Get with a function definition

  • To: mathgroup at smc.vnet.net
  • Subject: [mg81742] Re: using Save/Get with a function definition
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Tue, 2 Oct 2007 05:48:32 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <fdqd17$n5p$1@smc.vnet.net>

congruentialuminaire at yahoo.com wrote:

> I am trying to use" Get" with a function definition. I can guess I am
> not saving it properly. Any help is greatly appreciated. Here is my
> test:
> 
> Expand[(x+y)^3] >> tmp1
> 
> f[x_] := Sin[x]
> 
> % >> tmp1
> 
> (exit Mathematica)
> 
> (bring up Mathematica)
> 
> << tmp0
> 
> (shows expanded poly)
> 
> << tmp1
> 
> (no output)
> 
> ?f
> 
> Information::notfound: Symbol f not found. >>

The symbol << is a shortcut for the function *Put* that writes the 
result of the evaluation of an expression. A *SetDelayed* definition 
does not output anything (check the contents of the file tmp1: it 
contains the symbol NULL).

To save a function definition and its dependences, use *Save*. For instance,

(* First session *)
In[1]:= Expand[(x + y)^3] >> tmp0
f[x_] := Sin[x] >> tmp1
Save["tmp2", f]

(* Second session *)
In[1]:= << tmp0
<< tmp1
<< tmp2

Out[1]= x^3 + 3 x^2 y + 3 x y^2 + y^3

In[4]:= ?f

Global`f

f[x_]:=Sin[x]

In[5]:= f[2]

Out[5]= Sin[2]

Regards,
-- 
Jean-Marc


  • Prev by Date: Re: using Save/Get with a function definition
  • Next by Date: Re: Random Sequence Generation by Cellular Automata
  • Previous by thread: Re: using Save/Get with a function definition
  • Next by thread: Sort problem