This Julia package implements Hermite interpolation. It takes a list of interpolation points
Build an interpolation function with fit
:
x = [1.5, 2.5, 3.5]
y = [1, 0, -1]
yp = [0, 0, 0]
import HermiteInterpolation
f = HermiteInterpolation.fit(x, y, yp)
@assert f(1.5) ≈ 1.0
See that the interpolation function matches the data for both
using GLMakie
x_range = 1.2:0.02:3.8
lines(x_range, f.(x_range))
plot!(x, y; markersize=12, color=:red)
The interpolation function can be evaluated on any type that supports addition and multiplication. For example, DynamicPolynomials.jl can build the polynomial symbolically:
using DynamicPolynomials
@polyvar X
f_sym = f(X)
# -107.421875 + 246.09375X - 215.625X² + 91.25X³ - 18.75X⁴ + 1.5X⁵
fp_sym = differentiate(f_sym, X)
# 246.09375 - 431.25X + 273.75X² - 75.0X³ + 7.5X⁴
@assert f_sym(1.5) ≈ 1
@assert fp_sym(1.5) ≈ 0