In [9]:
println(readall(`cmd /c type lin_int.jl`))
In [2]:
include("lin_int.jl")
Out[2]:
In [3]:
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[3]:
In [4]:
g(x) = 2 .* cos(6x) .+ sin(14x) .+ 2.5
Out[4]:
In [21]:
units = [.25, .2, .1]
grids = [0:unit:1 for unit in units]
interps = [lin_int(grid, g(grid)) for grid in grids]
residuals = [x -> g(x) - interp(x) for interp in interps]
x =(1:99)/100
Out[21]:
In [23]:
using PyPlot
plot(x, g(x), label="original function")
for (interp, unit) in zip(interps, units)
plot(x, interp(x), label="linear interpolation by $(unit)")
end
legend()
Out[23]:
In [24]:
using PyPlot
for (residual, unit) in zip(residuals, units)
plot(x, residual(x), label="by $(unit)")
end
legend()
Out[24]:
In [ ]: