MathGroup Archive 2007

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

Search the Archive

Re: Functions with data hidden in them

Suppose I want a "dot" function that computes dot products of vectors with  
some fixed vector. One way to do this is:

Clear[makeDot, dot]
makeDot[v_?VectorQ] := dot[v]
dot[v_?VectorQ][x_?VectorQ] /; Length[v] == Length[x] := v.x

f = makeDot[{1, 1, 2}];
f[{a, b, c}]

a + b + 2 c

If the dimensions don't match, f returns unevaluated:

f[{a, b}]

dot[{1, 1, 2}][{a, b}]

makeDot and dot are analogous to Interpolation and InterpolatingFunction,  


On Thu, 04 Oct 2007 03:29:26 -0500, Neil Stewart  
<neil.stewart 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 take
s 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.


DrMajorBob at

  • Prev by Date: FrameLabel in v6.0
  • Next by Date: Re: Manipulate+Plot showing no output
  • Previous by thread: Re: Functions with data hidden in them
  • Next by thread: Re: Functions with data hidden in them