In [1]:
function g(x)
    grid = [2, 3]
    vals = [4, 6]
    interpolated_value = (vals[2]-vals[1])/(grid[2]-grid[1])*(x-grid[1])+vals[1]
    
    return interpolated_value
end


Out[1]:
g (generic function with 1 method)

In [5]:
grid = [2, 8]
vals = [4, 5]
f = lin_interp(grid, vals)

f(7)


Out[5]:
4.833333333333333

In [6]:



WARNING: Method definition lin_interp(Any, Any) in module Main at In[1]:2 overwritten at In[6]:2.
Out[6]:
lin_interp (generic function with 1 method)

In [2]:
function g(x)
    grid = [2, 3]
    vals = [4, 6]
    interpolated_value = (vals[2]-vals[1])/(grid[2]-grid[1])*(x-grid[1])+vals[1]
    
    return interpolated_value
end


Out[2]:
g (generic function with 1 method)

In [2]:
function lin_interp(grid, vals)
    function func(x)
        index_1 = searchsortedfirst(grid, x)
        index_2 = searchsortedlast(grid, x)
        x_1 = grid[index_1]
        x_2 = grid[index_2]
        y_1 = vals[index_1]
        y_2 = vals[index_2]
        
        y = ((y_2- y_1)/(x_2 - x_1))*(x - x_1) + y_1
        return y
    end
    return func
end

function h(grid, vals, x)
    i = searchsortedlast(grid, x)
    
    if i == 0 || i == length(grid)
        return 0
    end
    
    interpolated_value = (vals[i+1]-vals[i])/(grid[i+1]-grid[i])*(x-grid[i])+vals[i]
    
    return interpolated_value
end


Out[2]:
h (generic function with 1 method)

In [3]:
function ellenpola(grid, vals)
    function func(x)
        i = searchsortedlast(grid, x)
    
        if i == 0 || i == length(grid)
            return 0
        end

        interpolated_value = (vals[i+1]-vals[i])/(grid[i+1]-grid[i])*(x-grid[i])+vals[i]

        return interpolated_value

    end

    return func
end


Out[3]:
ellenpola (generic function with 1 method)

In [4]:
function ellenpola(grid, vals)
    function func(x)
    i = searchsortedlast(grid, x)
    if i == 0 || i == length(grid)
        return 0
    end
    interpolated_value = (vals[i+1]-vals[i])/(grid[i+1]-grid[i])*(x-grid[i])+vals[i]
    return interpolated_value
  end

    
    function func{T<:Real}(x::AbstractVector{T})
    n = length(x)
    out = Array(Float64, n)

    for i in 1:n
        i = searchsortedlast(grid, x)
        if i == 0 || i == length(grid)
            interpolated_value = 0
        else
            interpolated_value = (vals[i+1]-vals[i])/(grid[i+1]-grid[i])*(x-grid[i])+vals[i]
        end
        out[i] = interpolated_value
    end

    return out
   end
end


WARNING: Method definition ellenpola(Any, Any) in module Main at In[3]:2 overwritten at In[4]:2.
Out[4]:
ellenpola (generic function with 1 method)

In [13]:
function my_lin_interp(grid, vals)
    function func(x::Real)
        if x <= grid[1]
            index_1 = 1
            index_2 = 2
        elseif x >= grid[length(grid)]
            index_1 = length(grid) - 1
            index_2 = length(grid)
        else
            index_1 = searchsortedfirst(grid, x)
            index_2 = searchsortedlast(grid, x)
        end
        x_1 = grid[index_1]
        x_2 = grid[index_2]
        y_1 = vals[index_1]
        y_2 = vals[index_2]
        
        y = ((y_2- y_1)/(x_2 - x_1))*(x - x_1) + y_1
        return y
    end
    
    function func{T<:Real}(x::AbstractVector{T})
        y = zeros(length(x))
        for i in 1:length(x)
            y[i] = func(x[i])
        end
        return y
    end
    
    return func
end


Out[13]:
lin_interp (generic function with 1 method)

In [17]:
Pkg.clone("https://github.com/ellenjunghyunkim/MyInterpolations.jl")


INFO: Cloning MyInterpolations from https://github.com/ellenjunghyunkim/MyInterpolations.jl
MyInterpolations already exists

 in clone(::String, ::SubString{String}) at ./pkg/entry.jl:193
 in clone(::String) at ./pkg/entry.jl:221
 in (::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#clone,Tuple{String}})() at ./pkg/dir.jl:31
 in cd(::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#clone,Tuple{String}}, ::String) at ./file.jl:59
 in #cd#1(::Array{Any,1}, ::Function, ::Function, ::String, ::Vararg{Any,N}) at ./pkg/dir.jl:31
 in clone(::String) at ./pkg/pkg.jl:151

In [18]:
Pkg.test("MyInterpolations")


INFO: Testing MyInterpolations
ERROR: LoadError: UndefVarError: my_lin_interp not defined
 in include_from_node1(::String) at ./loading.jl:488
 in include_from_node1(::String) at /Users/ellen/Desktop/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
 in process_options(::Base.JLOptions) at ./client.jl:265
 in _start() at ./client.jl:321
 in _start() at /Users/ellen/Desktop/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
while loading /Users/ellen/.julia/v0.5/MyInterpolations/test/runtests.jl, in expression starting on line 4
==========================[ ERROR: MyInterpolations ]===========================

failed process: Process(`/Users/ellen/Desktop/Julia-0.5.app/Contents/Resources/julia/bin/julia -Ccore2 -J/Users/ellen/Desktop/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib --compile=yes --depwarn=yes --check-bounds=yes --code-coverage=none --color=yes --compilecache=yes /Users/ellen/.julia/v0.5/MyInterpolations/test/runtests.jl`, ProcessExited(1)) [1]

================================================================================
MyInterpolations had test errors

 in #test#61(::Bool, ::Function, ::Array{AbstractString,1}) at ./pkg/entry.jl:749
 in (::Base.Pkg.Entry.#kw##test)(::Array{Any,1}, ::Base.Pkg.Entry.#test, ::Array{AbstractString,1}) at ./<missing>:0
 in (::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#test,Tuple{Array{AbstractString,1}}})() at ./pkg/dir.jl:31
 in cd(::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#test,Tuple{Array{AbstractString,1}}}, ::String) at ./file.jl:59
 in #cd#1(::Array{Any,1}, ::Function, ::Function, ::Array{AbstractString,1}, ::Vararg{Array{AbstractString,1},N}) at ./pkg/dir.jl:31
 in (::Base.Pkg.Dir.#kw##cd)(::Array{Any,1}, ::Base.Pkg.Dir.#cd, ::Function, ::Array{AbstractString,1}, ::Vararg{Array{AbstractString,1},N}) at ./<missing>:0
 in #test#3(::Bool, ::Function, ::String, ::Vararg{String,N}) at ./pkg/pkg.jl:258
 in test(::String, ::Vararg{String,N}) at ./pkg/pkg.jl:258

In [11]:
Pkg.checkout("MyInterpolations", "master")


INFO: Checking out MyInterpolations master...
INFO: Pulling MyInterpolations latest master...
INFO: No packages to install, update or remove

In [12]:
Pkg.update("MyInterpolations", "master")


INFO: Updating METADATA...
INFO: Updating cache of PlotThemes...
Package master is not installed

 in partial_update_mask(::Dict{String,Tuple{VersionNumber,Bool}}, ::Dict{String,Dict{VersionNumber,Base.Pkg.Types.Available}}, ::Set{String}) at ./pkg/query.jl:74
 in update(::String, ::Set{String}) at ./pkg/entry.jl:399
 in (::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#update,Tuple{String,Set{String}}})() at ./pkg/dir.jl:31
 in cd(::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#update,Tuple{String,Set{String}}}, ::String) at ./file.jl:59
 in cd(::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#update,Tuple{String,Set{String}}}, ::String) at /Users/ellen/Desktop/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
 in #cd#1(::Array{Any,1}, ::Function, ::Function, ::String, ::Vararg{Any,N}) at ./pkg/dir.jl:31
 in update(::String, ::Vararg{String,N}) at ./pkg/pkg.jl:210

In [8]:
Pkg.checkout("MyInterpolations", "master")


INFO: Checking out MyInterpolations master...
INFO: Pulling MyInterpolations latest master...
INFO: No packages to install, update or remove

In [9]:
using MyInterpolations

In [10]:
Pkg.test("MyInterpolations")


INFO: Testing MyInterpolations
ERROR: LoadError: UndefVarError: my_lin_interp not defined
 in include_from_node1(::String) at ./loading.jl:488
 in include_from_node1(::String) at /Users/ellen/Desktop/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
 in process_options(::Base.JLOptions) at ./client.jl:265
 in _start() at ./client.jl:321
 in _start() at /Users/ellen/Desktop/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
while loading /Users/ellen/.julia/v0.5/MyInterpolations/test/runtests.jl, in expression starting on line 4
==========================[ ERROR: MyInterpolations ]===========================

failed process: Process(`/Users/ellen/Desktop/Julia-0.5.app/Contents/Resources/julia/bin/julia -Ccore2 -J/Users/ellen/Desktop/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib --compile=yes --depwarn=yes --check-bounds=yes --code-coverage=none --color=yes --compilecache=yes /Users/ellen/.julia/v0.5/MyInterpolations/test/runtests.jl`, ProcessExited(1)) [1]

================================================================================
MyInterpolations had test errors

 in #test#61(::Bool, ::Function, ::Array{AbstractString,1}) at ./pkg/entry.jl:749
 in (::Base.Pkg.Entry.#kw##test)(::Array{Any,1}, ::Base.Pkg.Entry.#test, ::Array{AbstractString,1}) at ./<missing>:0
 in (::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#test,Tuple{Array{AbstractString,1}}})() at ./pkg/dir.jl:31
 in cd(::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#test,Tuple{Array{AbstractString,1}}}, ::String) at ./file.jl:59
 in #cd#1(::Array{Any,1}, ::Function, ::Function, ::Array{AbstractString,1}, ::Vararg{Array{AbstractString,1},N}) at ./pkg/dir.jl:31
 in (::Base.Pkg.Dir.#kw##cd)(::Array{Any,1}, ::Base.Pkg.Dir.#cd, ::Function, ::Array{AbstractString,1}, ::Vararg{Array{AbstractString,1},N}) at ./<missing>:0
 in #test#3(::Bool, ::Function, ::String, ::Vararg{String,N}) at ./pkg/pkg.jl:258
 in test(::String, ::Vararg{String,N}) at ./pkg/pkg.jl:258

In [ ]: