MathGroup Archive 1998

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

Search the Archive

Re: Interpolation function objects



Sean Ross wrote:
> 
> If I define
> 
> f= Interpolation[data]
> 
> Then I can Plot[f[x],{x,xmin,xmax}] etc and f behaves like a regular
> function.
> 
> If I try and specify the argument in the definition of f as in
> 
> f[x_,n_Integer]:=Interpolation[data,InterpolationOrder->n]  or
> 
> f[#,n_Integer]:=Interpolation[data,InterpolationOrder->n]  or
> 
> f[x_]=Evaluate[Interpolation[data]][a]/.a->x  or
> 
> f[n_Integer]:=Interpolation[data,InterpolationOrder->n]
> 
> I get error messages.  I know the solution to this must deal with pure
> function constructs or Hold attributes, but I don't seem to be able to
> figure it out.  Can anyone help me?  Thanks.


Sean:

The following seem to work:

data = Table[{x,Sin[x]}//N,{x,0, 2Pi,Pi/5}];


f[x_,n_]:=Interpolation[data,InterpolationOrder->n][x]

f[x,4]

InterpolatingFunction[{{0, 6.28319}}, <>][x]

Plot[%,{x,0,2Pi}]


f[n_]:=Interpolation[data,InterpolationOrder->n]
	

f[4]

InterpolatingFunction[{{0, 6.28319}}, <>]

Plot[%[x],{x,0,2Pi}]

You might want to use the following to make a pure function

f[#,n_]:=Interpolation[data,InterpolationOrder->n]

f[4]

InterpolatingFunction[{{0, 6.28319}}, <>] -- 
Allan Hayes
Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642




  • Prev by Date: RE: Data Extraction from List {{x1,y1}..{xn,yn}}where ##<x<##
  • Next by Date: Re: Extension of MatrixExp
  • Prev by thread: Interpolation function objects
  • Next by thread: Re: Interpolation function objects