Piecewise linear interpolationΒΆ

We generate a piecewise linear interpolant of \(f(x)=e^{\sin 7x}\).

using FundamentalsNumericalComputation
f = x -> exp(sin(7*x))

plot(f,0,1,label="function",xlabel="x",ylabel="f(x)")

First we sample the function to create the data.

t = [0, 0.075, 0.25, 0.55, 0.7, 1]    # nodes
y = f.(t)                             # function values

scatter!(t,y,label="nodes")

Now we create a callable function that will evaluate the piecewise linear interpolant at any \(x\).

p = FNC.plinterp(t,y)
plot!(p,0,1,label="interpolant",title="PL interpolation")