In [1]:
using MyInterpolations

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


INFO: Testing MyInterpolations
Test Summary:                | Pass  Total
  Testing linear interporation |   13     13
INFO: MyInterpolations tests passed

In [3]:
using Plots
plotlyjs()

x = -7:7    # x points, coase grid
y = sin.(x)  # corresponding y points

xf = -7:0.1:7  # fine grid
plot(xf, sin.(xf), label="sine function")
scatter!(x, y, label="sampled data", markersize=4)


if !Plots.is_installed("PlotlyJS")
    Pkg.add("PlotlyJS")
end
if !Plots.is_installed("Rsvg")
    Pkg.add("Rsvg")
end
import Blink
Blink.AtomShell.install()


WARNING: Couldn't initialize plotlyjs.  (might need to install it?)
INFO: To do a standard install of plotlyjs, copy and run this:

ArgumentError: Module PlotlyJS not found in current path.
Run `Pkg.add("PlotlyJS")` to install the PlotlyJS package.

In [4]:
Pkg.add("PlotlyJS")


INFO: Cloning cache of Blink from https://github.com/JunoLab/Blink.jl.git
INFO: Cloning cache of Codecs from https://github.com/dcjones/Codecs.jl.git
INFO: Cloning cache of DataArrays from https://github.com/JuliaStats/DataArrays.jl.git
INFO: Cloning cache of DataFrames from https://github.com/JuliaStats/DataFrames.jl.git
INFO: Cloning cache of DocStringExtensions from https://github.com/JuliaDocs/DocStringExtensions.jl.git
INFO: Cloning cache of Hiccup from https://github.com/JunoLab/Hiccup.jl.git
INFO: Cloning cache of HttpCommon from https://github.com/JuliaWeb/HttpCommon.jl.git
INFO: Cloning cache of HttpParser from https://github.com/JuliaWeb/HttpParser.jl.git
INFO: Cloning cache of HttpServer from https://github.com/JuliaWeb/HttpServer.jl.git
INFO: Cloning cache of Juno from https://github.com/JunoLab/Juno.jl.git
INFO: Cloning cache of Lazy from https://github.com/MikeInnes/Lazy.jl.git
INFO: Cloning cache of Media from https://github.com/JunoLab/Media.jl.git
INFO: Cloning cache of Mustache from https://github.com/jverzani/Mustache.jl.git
INFO: Cloning cache of Mux from https://github.com/JuliaWeb/Mux.jl.git
INFO: Cloning cache of PlotlyJS from https://github.com/sglyon/PlotlyJS.jl.git
INFO: Cloning cache of SortingAlgorithms from https://github.com/JuliaCollections/SortingAlgorithms.jl.git
INFO: Cloning cache of WebSockets from https://github.com/JuliaWeb/WebSockets.jl.git
INFO: Installing Blink v0.5.2
INFO: Installing Codecs v0.3.0
INFO: Installing DataArrays v0.3.12
INFO: Installing DataFrames v0.9.1
INFO: Installing DocStringExtensions v0.3.3
INFO: Installing Hiccup v0.1.1
INFO: Installing HttpCommon v0.2.7
INFO: Installing HttpParser v0.2.0
INFO: Installing HttpServer v0.2.0
INFO: Installing Juno v0.2.7
INFO: Installing LaTeXStrings v0.2.1
INFO: Installing Lazy v0.11.6
INFO: Installing MacroTools v0.3.6
INFO: Installing Media v0.2.7
INFO: Installing Mustache v0.1.4
INFO: Installing Mux v0.2.3
INFO: Installing PlotlyJS v0.6.2
INFO: Installing SortingAlgorithms v0.1.1
INFO: Installing WebSockets v0.2.2
INFO: Building HttpParser
WARNING: BinDeps.shlib_ext is deprecated.
  likely near /Users/ellen/.julia/v0.5/HttpParser/deps/build.jl:38
INFO: Attempting to Create directory /Users/ellen/.julia/v0.5/HttpParser/deps/downloads
INFO: Attempting to Create directory /Users/ellen/.julia/v0.5/HttpParser/deps/downloads
INFO: Directory /Users/ellen/.julia/v0.5/HttpParser/deps/downloads already created
INFO: Downloading file https://github.com/nodejs/http-parser/archive/v2.7.1.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   123    0   123    0     0     33      0 --:--:--  0:00:03 --:--:--   199
  0     0    0     0    0     0      0      0 --:--:--  0:00:03 --:--:--     0
Archive:  /Users/ellen/.julia/v0.5/HttpParser/deps/downloads/v2.7.1.zip
feae95a3a69f111bc1897b9048d9acbc290992f9
100 55365  100 55365    0     0  12289      0  0:00:04  0:00:04 --:--:-- 67027
INFO: Done downloading file https://github.com/nodejs/http-parser/archive/v2.7.1.zip
INFO: Attempting to Create directory /Users/ellen/.julia/v0.5/HttpParser/deps
INFO: Directory /Users/ellen/.julia/v0.5/HttpParser/deps already created
   creating: /Users/ellen/.julia/v0.5/HttpParser/deps/src/http-parser-2.7.1/
  inflating: /Users/ellen/.julia/v0.5/HttpParser/deps/src/http-parser-2.7.1/.gitignore  
  inflating: /Users/ellen/.julia/v0.5/HttpParser/deps/src/http-parser-2.7.1/.mailmap  
  inflating: /Users/ellen/.julia/v0.5/HttpParser/deps/src/http-parser-2.7.1/.travis.yml  
  inflating: /Users/ellen/.julia/v0.5/HttpParser/deps/src/http-parser-2.7.1/AUTHORS  
  inflating: /Users/ellen/.julia/v0.5/HttpParser/deps/src/http-parser-2.7.1/LICENSE-MIT  
  inflating: /Users/ellen/.julia/v0.5/HttpParser/deps/src/http-parser-2.7.1/Makefile  
  inflating: /Users/ellen/.julia/v0.5/HttpParser/deps/src/http-parser-2.7.1/README.md  
  inflating: /Users/ellen/.julia/v0.5/HttpParser/deps/src/http-parser-2.7.1/bench.c  
   creating: /Users/ellen/.julia/v0.5/HttpParser/deps/src/http-parser-2.7.1/contrib/
  inflating: /Users/ellen/.julia/v0.5/HttpParser/deps/src/http-parser-2.7.1/contrib/parsertrace.c  
  inflating: /Users/ellen/.julia/v0.5/HttpParser/deps/src/http-parser-2.7.1/contrib/url_parser.c  
  inflating: /Users/ellen/.julia/v0.5/HttpParser/deps/src/http-parser-2.7.1/http_parser.c  
  inflating: /Users/ellen/.julia/v0.5/HttpParser/deps/src/http-parser-2.7.1/http_parser.gyp  
  inflating: /Users/ellen/.julia/v0.5/HttpParser/deps/src/http-parser-2.7.1/http_parser.h  
  inflating: /Users/ellen/.julia/v0.5/HttpParser/deps/src/http-parser-2.7.1/test.c  
cc  -I. -DHTTP_PARSER_STRICT=0  -Wall -Wextra -Werror -O3  -fPIC -c http_parser.c -o libhttp_parser.o
INFO: Attempting to Create directory /Users/ellen/.julia/v0.5/HttpParser/deps/usr/lib
INFO: Changing Directory to /Users/ellen/.julia/v0.5/HttpParser/deps/src/http-parser-2.7.1
INFO: Changing Directory to /Users/ellen/.julia/v0.5/HttpParser/deps/src/http-parser-2.7.1
INFO: Changing Directory to /Users/ellen/.julia/v0.5/HttpParser/deps/src
INFO: Attempting to Create directory /Users/ellen/.julia/v0.5/HttpParser/deps/usr/lib
INFO: Directory /Users/ellen/.julia/v0.5/HttpParser/deps/usr/lib already created
INFO: Changing Directory to /Users/ellen/.julia/v0.5/HttpParser/deps/src
cc  -shared -o libhttp_parser.dylib libhttp_parser.o
INFO: Changing Directory to /Users/ellen/.julia/v0.5/HttpParser/deps/src
INFO: Building Homebrew
Updated 2 taps (homebrew/core, homebrew/science).
==> New Formulae
allure
antlr4-cpp-runtime
audacious
bdsup2sub
chronograf
cockroach
dcos-cli
mono-libgdiplus
moodbar
percona-server-mongodb
twine-pypi
warp
==> Updated Formulae
ammonite-repl
antigen
apache-archiva
apache-brooklyn-cli
arangodb
aria2
aws-sdk-cpp
awscli
bandcamp-dl
bit
bitlbee
bluepill
caddy
carthage
certbot
certigo
citus
cnats
coffeescript
convox
creduce
datomic
deis
dhall-json
diffutils
digdag
doctl
dropbear
elixir
etcd
exa
exiftool
fades
ffmpeg
fio
firebase-cli
flint-checker
folly
fonttools
freetds
fwup
geoip
geoserver
gist
git-annex
git-flow-avh
git-lfs
git-town
glib
gmime
gnupg
gobject-introspection
gofabric8
grails@2.5
grc
grpc
gtk+3
gtk-vnc
gtksourceview3
halibut
homebank
homebrew/science/adapterremoval
homebrew/science/bcftools
homebrew/science/dealii
homebrew/science/etsf_io
homebrew/science/getdp
homebrew/science/gmsh
homebrew/science/htslib
homebrew/science/hypre
homebrew/science/lastz
homebrew/science/openimageio
homebrew/science/paraview
homebrew/science/topcat
homebrew/science/vigra
homebrew/science/vips
homebrew/science/wiggletools
homebrew/science/xmgredit
homebrew/science/xmi-msim
imagemagick
imagemagick@6
immortal
infer
inspircd
ipfs
jasper
jbig2dec
jenkins
jlog
jo
kops
kubernetes-cli
kubernetes-helm
leaps
libaacs
libatomic_ops
libcouchbase
libfabric
libmaxminddb
libphonenumber
linkerd
logrotate
luvit
makensis
minicom
minidlna
minimal-racket
miniupnpc
minizinc
mkvtoolnix
mldonkey
monax
mongoose
mono
mpd
mps-youtube
mysql-connector-c++
mysqltuner
nano
nativefier
nginx
nim
npth
ode
open-scene-graph
openshift-cli
openvpn
par2
parallel
pegtl
perl-build
pmd
pre-commit
prometheus
pyenv
quantlib
radare2
redis
redpen
rkflashtool
rocksdb
roswell
rrdtool
saltstack
scala@2.11
shc
shellshare
skinny
sourcekitten
sphinx-doc
swi-prolog
syncthing
sysbench
sysdig
tarantool
tbb
tcpreplay
tcptraceroute
tee-clc
telegraf
testssl
tiger-vnc
tor
traildb
tth
uncrustify
unrar
urh
vagrant-completion
varnish
varnish@4
vim
watchexec
weechat
winetricks
wireguard-tools
yarn
ykpers
youtube-dl
Using system libraries...
INFO: Building MbedTLS
INFO: Building PlotlyJS
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  741k    0  741k    0     0   700k      0 --:--:--  0:00:01 --:--:--  710k
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 2194k  100 2194k    0     0  1364k      0  0:00:01  0:00:01 --:--:-- 1375k
INFO: Package database updated
INFO: METADATA is out-of-date — you may not have the latest version of PlotlyJS
INFO: Use `Pkg.update()` to get the latest versions of your packages

In [5]:
using Plots
plotlyjs()

x = -7:7    # x points, coase grid
y = sin.(x)  # corresponding y points

xf = -7:0.1:7  # fine grid
plot(xf, sin.(xf), label="sine function")
scatter!(x, y, label="sampled data", markersize=4)


INFO: Precompiling module PlotlyJS.
WARNING: using Lazy.remove in module AtomShell conflicts with an existing identifier.
WARNING: Method definition describe(AbstractArray) in module StatsBase at /Users/ellen/.julia/v0.5/StatsBase/src/scalarstats.jl:573 overwritten in module DataFrames at /Users/ellen/.julia/v0.5/DataFrames/src/abstractdataframe/abstractdataframe.jl:407.
WARNING: Method definition describe(AbstractArray) in module StatsBase at /Users/ellen/.julia/v0.5/StatsBase/src/scalarstats.jl:573 overwritten in module DataFrames at /Users/ellen/.julia/v0.5/DataFrames/src/abstractdataframe/abstractdataframe.jl:407.

Plotly javascript loaded.

To load again call

init_notebook(true)

WARNING: Method definition describe(AbstractArray) in module StatsBase at /Users/ellen/.julia/v0.5/StatsBase/src/scalarstats.jl:573 overwritten in module DataFrames at /Users/ellen/.julia/v0.5/DataFrames/src/abstractdataframe/abstractdataframe.jl:407.
Out[5]:

In [11]:
li = LinearInterpolation(x, y)        # create LinInterp object
li(0.3)                     # evaluate at a single point
y_linear_qe = li.(xf)       # evaluate at multiple points

plot(xf, y_linear_qe, label="linear")
scatter!(x, y, label="sampled data", markersize=4)


Out[11]:

In [12]:
f(x) = 2 .* cos.(6x) .+ sin.(14x) .+ 2.5
c_grid = 0:.2:1
n = length(c_grid)

Af = LinearInterpolation(c_grid, f(c_grid))

f_grid = linspace(0, 1, 150)

plot(f_grid, f, color=:blue, linewidth=2, alpha=0.8, label="true function")
plot!(f_grid, Af.(f_grid), color=:green, linewidth=2, alpha=0.8,
      label="linear approximation", legend=:top, grid=false)
N = repmat(c_grid, 1, 2)'
heights = [zeros(1,n); f(c_grid)']
plot!(N, heights, color=:black, linestyle=:dash, alpha=0.5, label="")


Out[12]:

In [ ]: