Re: Interpolation function objects
- To: mathgroup@smc.vnet.net
- Subject: [mg11739] Re: Interpolation function objects
- From: Allan Hayes <hay@haystack.demon.co.uk>
- Date: Thu, 26 Mar 1998 03:09:06 -0500
- References: <6f1mph$fb6@smc.vnet.net>
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