Piecewise polynomial interpolationΒΆ
Let us repeat the data from Poor conditioning in polynomial interpolation but use piecewise polynomials constructed using the Interpolations
package.
using FundamentalsNumericalComputation
n = 12
t = LinRange(-1,1,n+1)
y = @. t^2 + t + 0.5*sin(20*t)
scatter(t,y,label="data",leg=:top)
Here is an interpolant that is linear between each pair of consecutive nodes.
p = LinearInterpolation(t,y)
plot!(x->p(x),-1,1,label="piecewise linear")
We may instead request a smoother interpolant that is piecewise cubic.
p = CubicSplineInterpolation(t,y)
plot!(x->p(x),-1,1,label="piecewise cubic")