In [3]:
using MyInterpolations
In [4]:
grid =[1, 2, 3, 4, 5, 6, 7, 8]
vals = [2, 0, 4, -1, 3, 7, 3, 10]
f = lin_int(grid,vals)
f.([0,1, 2.7, 7.5, 8.1])
Out[4]:
In [5]:
Pkg.test("MyInterpolations")
In [6]:
using Plots
plotlyjs()
Out[6]:
In [7]:
x = linspace(-7,7,10) # x points, coase grid
y = sin.(x) # corresponding y points
xf = -7:0.1:7 # fine grid
plot(xf, sin.(xf), label="sine function")
plot!(x, y, st=:scatter, label="sampled data", markersize=4)
Out[7]:
In [8]:
li = lin_int(x, y)
y_linear_qe = li.(xf) # evaluate at multiple points
plot(xf, sin.(xf), label="sine function")
plot!(xf, y_linear_qe, label="linear interpolation")
scatter!(x, y, label="sampled data", markersize=4)
Out[8]:
In [9]:
samples = [10,20,30]
grids = [linspace(-7,7,sample) for sample in samples]
interps = [lin_int(grid, sin.(grid)) for grid in grids]
Out[9]:
In [10]:
labels1 = Array{String}(1, 3)
for (i, sample) in enumerate(samples)
labels1[i] = "linear interpolation at $sample times"
end
In [11]:
plot(xf, [interps[i].(xf) for i in 1:3], label = labels1)
plot!(xf, sin.(xf), label = "sine function")
Out[11]:
In [12]:
labels2 = Array{String}(1, 3)
for (i, sample) in enumerate(samples)
labels2[i] = "residual at $sample times"
end
In [13]:
plot(xf, [sin.(xf) - interps[i].(xf) for i in 1:3], label = labels2)
Out[13]: