-- a step sampled at x = 0, 1, ..., 10, interpolated in three ways x, y = {}, {} for i = 0, 10 do x[i+1] = i; y[i+1] = (i < 5) and 0 or 1 end S = InterpolatingFunction.Spline(x, y) H = InterpolatingFunction.HermiteCSpline(x, y) B = InterpolatingFunction.BSpline(x, y, 5) -- the smallest and the largest value between the data points for _, f in ipairs({S, H, B}) do local min, max = 0, 1 for i = 0, 1000 do local v = f(i/100) min, max = math.min(min, v), math.max(max, v) end print(string.format("%-14s degree %d min %8.4f max %8.4f", f.type, f.degree, min, max)) end -- the three curves, and the data as dots function Curve(f) local c = {} for i = 0, 400 do c[i+1] = {i/40, f(i/40)} end return c end Dots = {} for i = 1, #x do Dots[i] = {x[i], y[i]} end pl = Graphics.Plot({Curve(S), Curve(H), Curve(B), Dots}, {{"plotIm", false}, {"LineStyle", {{}, {}, {}, {{"LineWidth", 0}, {"PointSize", 0.006}, {"PointColor", 0x000000}}}}, {"Frame", {{"Xmin", 0}, {"Xmax", 10}, {"Ymin", -0.3}, {"Ymax", 1.3}, {"FirstYTick", 0}, {"dYTick", 0.5}, {"YFormat", "%.1f"}, {"XLabel", "x"}, {"YLabel", "f(x)"}, {"XLMargin", 0.1}, {"YAxis", -10}}}}) file = io.open("interpolation_types.svg", "w") file:write(Graphics.ToSVG(pl, {{"RelativeSize", true}})) file:close()