this is kinda obvious, so i suspect it's not what you want, but just in 
case...

function make_interp(x, y)
    function interp(x2)
        @assert x2 > x[1] && x2 < x[end]
        i = 1
        while x[i] < x2; i += 1; end
        (x[i] - x2) * y[i-1] + (x2 - x[i-1]) * y[i]
    end
end

x = [1,2,3,4,5]
y = [x2^2 for x2 in x]

my_interp = make_interp(x, y)
println(my_interp(2.1))  # prints 4.5                           

andrew


On Tuesday, 25 February 2014 17:17:24 UTC-3, Marek Gagolewski wrote:
>
> On Tuesday, February 25, 2014 5:16:13 PM UTC+1, Tim Holy wrote:
>>
>> First, are you looking for anonymous functions? 
>> http://docs.julialang.org/en/latest/manual/functions/#anonymous-functions 
>>
>> Second, I suspect Grid.jl already does exactly what you're asking re 
>> interpolation. 
>> https://github.com/timholy/Grid.jl 
>>
>
> Thanks Tim, but I think that's not the case. I'd like to create a function 
> that returns an interpolating function (independent of the objects which 
> were used to create it). I don't think it's directly possible in Grid 
> (except for a []-like hack that Stefan mentioned). It only partially suits 
> my needs, unfortunately.
>
> Among similar functions in R that obey this property I find approxfun, 
> splinefun, and ecdf (each one aiming at some kind of point interpolation)
>

Reply via email to