Re: Functions with data hidden in them

*To*: mathgroup at smc.vnet.net*Subject*: [mg81870] Re: Functions with data hidden in them*From*: markholtuk at googlemail.com*Date*: Fri, 5 Oct 2007 04:54:20 -0400 (EDT)*References*: <fe28v5$muq$1@smc.vnet.net>

Hi Neil, I'm not exactly sure what you want, so this probably isn't what you mean (I'm sure others will give you the answer you need), however I thought I'd share this neat trick with you that I use sometimes to hide/store/transfer data and/or code. The first step is to create a button containing your data (in Mathematica 6.0) as follows: Button["data", {data = Interpolation[Table[Sin[x], {x, 0, 2 Pi}]]}] Quit the kernel to remove any references to data and then press the button. Next type data and evaluate: In[1]:= data Out[1]= InterpolatingFunction[{{1,7}},<>] Then pull some values out from this: In[2]:= data[1] data[1.5] data[2] Out[2]= 0 Out[3]= 0.513544 Out[4]= Sin[1] You can do something similar with ButtonBox in Mathematica 5.2, but it's not as straightforward. Sorry if that was not what you wanted, but maybe you'll find some use for it! Mark Mark R. Holt, BA, PhD, Room 3.28 Molecular Cardiology, Cardiovascular Division and Randall Division of Cell and Molecular Biophysics, New Hunt's House, King's College London, Guy's Hospital Campus, LONDON, SE1 1UL. Phone: +44 20 7848 6438 Fax: +44 20 7848 6435 On Oct 4, 9:41 am, Neil Stewart <neil.stew... at warwick.ac.uk> wrote: > The Interpolation[] function somehow "hides" the data passed to it in the > InterpolationFunction object that it returns. In the example below, when > f[1] is evaluated it is using information from the list data, but does not > have the list data passed to it as parameter. > > In[1]:= data = {{1, 1}, {2, 2}, {3, 3}} > > In[2]:= f = Interpolation[data] > > In[3]:= f[1] > Out[3]= 1 > > How can I write my own function that stores data inside itself in the same > way that Interpolation does? I'm aiming to write a functions that takes a > number as a parameter and consults a large data set to return a number. I'm > not sure where to start - any ideas very welcome! > > Thanks, > Neil.