In [15]:
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[15]:
g (generic function with 1 method)

In [ ]:


In [16]:
print(g(2.5))


5.0

In [17]:
grid = [-2, 1, 4, 6, 7, 10]
println(grid)

searchsortedlast(grid, 5.5)


[-2,1,4,6,7,10]
Out[17]:
3

In [21]:
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[21]:
h (generic function with 1 method)

In [22]:
grid = [0, 2, 4, 6, 8, 10]
vals = [1, 4, 5, 8, 9, 11]
println(h(grid, vals, 3))


4.5

In [24]:
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[24]:
ellenpola (generic function with 1 method)

In [25]:
grid = [0, 2, 4, 6, 8, 10]
vals = [1, 4, 5, 8, 9, 11]
my_func = ellenpola(grid,vals)
my_func(3)


Out[25]:
4.5

In [26]:
my_func(7)


Out[26]:
8.5

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


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

In [22]:
grid = [0, 2, 4, 6, 8, 10]
vals = [1, 4, 5, 8, 9, 11]
my_func = ellenpola(grid,vals)

println(my_func(1))
println(my_func(7))
println(my_func(11))


2.5
8.5
AbstractArray{T,1}

In [2]:
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


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

In [10]:
module MyLinInterp

  export LinearInterpolation

  immutable LinearInterpolation 
    grid::Array
    vals::Array
 end

 function call(a::LinearInterpolation, x::Real)
    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 call{T<:Real}(a::LinearInterpolation, 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: replacing module MyLinInterp
Out[10]:
MyLinInterp

In [1]:
Pkg.add(MyInterpolations)


LoadError: UndefVarError: MyInterpolations not defined
while loading In[1], in expression starting on line 1

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


INFO: Checking out MyInterpolations master...
INFO: Pulling MyInterpolations latest master...
WARNING: julia is fixed at 0.4.5 conflicting with requirement for MyInterpolations: [0.5.0,∞)
INFO: No packages to install, update or remove

In [6]:
Pkg.rm("MyInterpolations")


INFO: Removing MyInterpolations (unregistered)

In [7]:
Pkg.rm("MyInterpolations")


INFO: Nothing to be done

In [8]:
Pkg.update()


INFO: Updating METADATA...
INFO: Updating cache of BinDeps...
INFO: Updating cache of StatsBase...
INFO: Updating cache of Distributions...
INFO: Updating cache of Compat...
INFO: Updating cache of JSON...
INFO: Updating cache of PyPlot...
INFO: Updating cache of PyCall...
INFO: Updating cache of Nettle...
INFO: Updating cache of LaTeXStrings...
INFO: Computing changes...
INFO: Cloning cache of MacroTools from git://github.com/MikeInnes/MacroTools.jl.git
INFO: Upgrading BinDeps: v0.3.21 => v0.4.7
INFO: Installing Calculus v0.2.2
INFO: Upgrading ColorTypes: v0.2.2 => v0.2.12
INFO: Upgrading Colors: v0.6.3 => v0.6.9
INFO: Upgrading Compat: v0.7.14 => v0.25.2
INFO: Upgrading Conda: v0.1.9 => v0.5.3
INFO: Upgrading Distributions: v0.8.10 => v0.11.1
INFO: Upgrading FixedPointNumbers: v0.1.3 => v0.2.1
INFO: Upgrading Homebrew: v0.2.0 => v0.5.6
INFO: Upgrading IJulia: v1.1.9 => v1.4.1
INFO: Upgrading JSON: v0.5.0 => v0.9.1
INFO: Upgrading LaTeXStrings: v0.1.6 => v0.2.1
INFO: Installing MacroTools v0.3.6
INFO: Upgrading Nettle: v0.2.3 => v0.3.0
INFO: Upgrading PDMats: v0.4.1 => v0.6.0
INFO: Upgrading PyCall: v1.4.0 => v1.11.1
INFO: Upgrading PyPlot: v2.1.1 => v2.3.2
INFO: Installing Rmath v0.1.6
INFO: Upgrading SHA: v0.1.2 => v0.3.2
INFO: Upgrading StatsBase: v0.8.0 => v0.12.0
INFO: Upgrading StatsFuns: v0.2.0 => v0.4.0
INFO: Upgrading URIParser: v0.1.3 => v0.1.8
INFO: Upgrading ZMQ: v0.3.1 => v0.4.2
INFO: Removing ArrayViews v0.6.4
INFO: Removing Dates v0.4.4
INFO: Building Conda
INFO: Recompiling stale cache file /Users/ellen/.julia/lib/v0.4/Compat.ji for module Compat.
INFO: Building Rmath
INFO: Recompiling stale cache file /Users/ellen/.julia/lib/v0.4/BinDeps.ji for module BinDeps.
INFO: Recompiling stale cache file /Users/ellen/.julia/lib/v0.4/URIParser.ji for module URIParser.
INFO: Recompiling stale cache file /Users/ellen/.julia/lib/v0.4/SHA.ji for module SHA.
INFO: Building Homebrew
INFO: Recompiling stale cache file /Users/ellen/.julia/lib/v0.4/JSON.ji for module JSON.
warning: no common commits
From https://github.com/Homebrew/brew
 + 21ce7a5...7000f50 master     -> origin/master  (forced update)
HEAD is now at 7000f50 Merge pull request #2646 from sjackman/replace_text_in_files
/Users/ellen/.julia/v0.4/Homebrew/deps/usr/Library/Homebrew/cmd/update.sh: line 6: /Users/ellen/.julia/v0.4/Homebrew/deps/usr/Library/ENV/scm/git: No such file or directory
==============================[ ERROR: Homebrew ]===============================

LoadError: failed process: Process(`/Users/ellen/.julia/v0.4/Homebrew/deps/usr/bin/brew update --force`, ProcessExited(1)) [1]
while loading /Users/ellen/.julia/v0.4/Homebrew/deps/build.jl, in expression starting on line 2

================================================================================
INFO: Building Nettle
INFO: Building ZMQ
INFO: Building IJulia
INFO: Recompiling stale cache file /Users/ellen/.julia/lib/v0.4/Conda.ji for module Conda.
INFO: Installing Jupyter via the Conda package.
Fetching package metadata: ....
Solving package specifications: .........

Package plan for installation in environment /Users/ellen/.julia/v0.4/Conda/deps/usr:

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    conda-env-2.6.0            |                0          601 B
    sqlite-3.13.0              |                0         1.4 MB
    python-2.7.13              |                0         9.1 MB
    asn1crypto-0.22.0          |           py27_0         145 KB
    enum34-1.1.6               |           py27_0          54 KB
    idna-2.5                   |           py27_0         121 KB
    ipaddress-1.0.18           |           py27_0          30 KB
    pycparser-2.17             |           py27_0         153 KB
    pyparsing-2.1.4            |           py27_0          70 KB
    requests-2.12.4            |           py27_0         752 KB
    ruamel_yaml-0.11.14        |           py27_1         197 KB
    cffi-1.10.0                |           py27_0         195 KB
    packaging-16.8             |           py27_0          29 KB
    cryptography-1.8.1         |           py27_0         468 KB
    pyopenssl-17.0.0           |           py27_0          73 KB
    conda-4.3.18               |           py27_0         492 KB
    jupyter-1.0.0              |           py27_3           3 KB
    ------------------------------------------------------------
                                           Total:        13.2 MB

The following NEW packages will be INSTALLED:

    asn1crypto:   0.22.0-py27_0 
    cffi:         1.10.0-py27_0 
    cryptography: 1.8.1-py27_0  
    enum34:       1.1.6-py27_0  
    idna:         2.5-py27_0    
    ipaddress:    1.0.18-py27_0 
    packaging:    16.8-py27_0   
    pycparser:    2.17-py27_0   
    pyopenssl:    17.0.0-py27_0 
    pyparsing:    2.1.4-py27_0  
    ruamel_yaml:  0.11.14-py27_1

The following packages will be UPDATED:

    conda:        4.0.5-py27_0 --> 4.3.18-py27_0 
    conda-env:    2.4.5-py27_0 --> 2.6.0-0       
    jupyter:      1.0.0-py27_2 --> 1.0.0-py27_3  
    python:       2.7.11-0     --> 2.7.13-0      
    requests:     2.9.1-py27_0 --> 2.12.4-py27_0 
    sqlite:       3.9.2-0      --> 3.13.0-0      

Fetching packages ...
conda-env-2.6. 100% |###############################| Time: 0:00:00 363.12 kB/s
sqlite-3.13.0- 100% |###############################| Time: 0:00:25  56.57 kB/s
python-2.7.13- 100% |###############################| Time: 0:01:56  82.28 kB/s 0:00:26  51.52 kB/s         | Time: 0:01:04  72.97 kB/s####################     | Time: 0:01:38  81.66 kB/s
asn1crypto-0.2 100% |###############################| Time: 0:00:00 286.12 kB/s
enum34-1.1.6-p 100% |###############################| Time: 0:00:00 240.08 kB/s
idna-2.5-py27_ 100% |###############################| Time: 0:00:00 163.37 kB/s
ipaddress-1.0. 100% |###############################| Time: 0:00:00 246.08 kB/s
pycparser-2.17 100% |###############################| Time: 0:00:00 285.04 kB/s
pyparsing-2.1. 100% |###############################| Time: 0:00:00 106.85 kB/s
requests-2.12. 100% |###############################| Time: 0:00:14  54.30 kB/s
ruamel_yaml-0. 100% |###############################| Time: 0:00:01 182.39 kB/smel_yaml-0.   8% |##                             | Time: 0:00:00 229.93 kB/s
cffi-1.10.0-py 100% |###############################| Time: 0:00:02  96.79 kB/s
packaging-16.8 100% |###############################| Time: 0:00:00  77.29 kB/s
cryptography-1 100% |###############################| Time: 0:00:06  78.17 kB/s
pyopenssl-17.0 100% |###############################| Time: 0:00:00 184.94 kB/s
conda-4.3.18-p 100% |###############################| Time: 0:00:02 175.59 kB/s
jupyter-1.0.0- 100% |###############################| Time: 0:00:00   2.29 MB/s
Extracting packages ...
[      COMPLETE      ]|##################################################| 100%
Unlinking packages ...
[      COMPLETE      ]|##################################################| 100%
Linking packages ...
[      COMPLETE      ]|##################################################| 100%
INFO: Found Jupyter version 4.1.0: /Users/ellen/.julia/v0.4/Conda/deps/usr/bin/jupyter
Writing IJulia kernelspec to /Users/ellen/.julia/v0.4/IJulia/deps/julia-0.4/kernel.json ...
Installing julia kernelspec julia-0.4
[InstallKernelSpec] Removing existing kernelspec in /Users/ellen/Library/Jupyter/kernels/julia-0.4
[InstallKernelSpec] Installed kernelspec julia-0.4 in /Users/ellen/Library/Jupyter/kernels/julia-0.4
INFO: Building PyCall
INFO: PyCall is using /usr/bin/python (Python 2.7.10) at /usr/bin/python, libpython = /System/Library/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7
INFO: /Users/ellen/.julia/v0.4/PyCall/deps/deps.jl has been updated
INFO: /Users/ellen/.julia/v0.4/PyCall/deps/PYTHON has been updated

================================[ BUILD ERRORS ]================================

WARNING: Homebrew had build errors.

 - packages with build errors remain installed in /Users/ellen/.julia/v0.4
 - build the package(s) and all dependencies with `Pkg.build("Homebrew")`
 - build a single package by running its `deps/build.jl` script

================================================================================

In [ ]: