MathGroup Archive 2007

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

Search the Archive

Re: Functions with data hidden in them

  • To: mathgroup at
  • Subject: [mg81870] Re: Functions with data hidden in them
  • From: markholtuk at
  • Date: Fri, 5 Oct 2007 04:54:20 -0400 (EDT)
  • References: <fe28v5$muq$>

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

Next type data and evaluate:

In[1]:= data

Out[1]= InterpolatingFunction[{{1,7}},<>]

Then pull some values out from this:

In[2]:= data[1]

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 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,

Phone: +44 20 7848 6438
Fax:     +44 20 7848 6435

On Oct 4, 9:41 am, Neil Stewart <neil.stew... at> 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.

  • Prev by Date: Re: Strange result for a definite integral: Unknown Symbol
  • Next by Date: Re: Re: Problems with PlotStyle in ListPointPlot3D
  • Previous by thread: Re: Functions with data hidden in them
  • Next by thread: Re: Functions with data hidden in them