-- two functions on different points x1, x2 = {0, 0.4, 1.1, 1.6, 2.3, 3}, {0, 0.7, 1.5, 2.2, 3} function Table(f, x) local y = {} for i = 1, #x do y[i] = f(x[i]) end return y end for _, name in ipairs({"Spline", "HermiteCSpline"}) do local f = InterpolatingFunction[name](x1, Table(math.exp, x1)) local g = InterpolatingFunction[name](x2, Table(math.sin, x2)) local s, p = f + g, f * g local es, ep = 0, 0 for i = 0, 300 do local t = i/100 es = math.max(es, math.abs(s(t) - (f(t) + g(t)))) ep = math.max(ep, math.abs(p(t) - f(t)*g(t))) end print(string.format("%-14s f+g: %d points, max |(f+g)(t) - f(t) - g(t)| = %.1e; f*g: max |(f*g)(t) - f(t) g(t)| = %.1e", name, #s.x, es, ep)) end