-- an occupation that rises from 0 to 1, sampled at 8 points x = {0, 1, 2, 2.5, 3, 3.5, 4, 6} y = {0, 0, 0.05, 0.4, 0.9, 1, 1, 1} S = InterpolatingFunction.Spline(x, y) H = InterpolatingFunction.HermiteCSpline(x, y) for _, f in ipairs({S, H}) do local min, max = 0, 1 for i = 0, 600 do local v = f(i/100) min, max = math.min(min, v), math.max(max, v) end print(string.format("%-14s min %8.4f max %8.4f", f.type, min, max)) end -- with the exact slopes a cubic Hermite spline reproduces every cubic polynomial p = function(t) return 1 + t - 2*t^2 + 0.5*t^3 end dp = function(t) return 1 - 4*t + 1.5*t^2 end yp, mp = {}, {} for i = 1, #x do yp[i] = p(x[i]); mp[i] = dp(x[i]) end P = InterpolatingFunction.HermiteCSpline(x, yp, mp) print(string.format("cubic with exact slopes: P(4.7) - p(4.7) = %.1e", P(4.7) - p(4.7)))