Suppose we are given two interpolated functions
f1 = Interpolation[{{0, 0}, {1, 2}, {3, 5}, {4, 2}, {8, -1}}, InterpolationOrder -> 0];
f2 = Interpolation[{{0, 0}, {1, 3}, {3, 7}, {4, 2}, {8, 0}}, InterpolationOrder -> 1];
and one derived function
f3 = FunctionInterpolation[f1[t] - f2[t], {t, 0., 8.}];
Plotting those functions shows that f3 is not a very accurate representation of the result.
Plot[{f1[t], f2[t], f1[t] - f2[t], f3[t]}, {t, 0, 8}]
This can be improved by defining f3 as follows
f3 = FunctionInterpolation[
f1[t] - f2[t],
{t, 0., 8.},
InterpolationPoints -> 300,
InterpolationOrder -> 1
];
but at the cost of oversampling.
A simple but rather hacky way to represent f3 more accurately without oversampling is
f3 = Interpolation[
Cases[Plot[f1[t] - f2[t], {t, 0, 8}], Line[_], Infinity][[1, 1]],
InterpolationOrder -> 1
]
I also tried to construct an InterpolatingFunction from MeshCoordinates@DiscretizeRegion@ImplicitRegion[f1[t] - f2[t] == y, {{t, 0, 8}, {y, -6, 3}}]. However, this does not work out of the box because points are duplicated due to the presence of discontinuities.
How would you approach the problem?
Update: The following use case is one example where accurate and efficient sampling is necessary. Suppose the dependent variable represents a date (AbsoluteTime[DateObject[...]]) and the goal is to construct a TimeSeries object of f1[t] + f2[t] that takes interpolation into account.



f1[t] - f2[t]? – cvgmt Dec 14 '22 at 01:44f1[t] + f2[t]takes interpolation into account and could be used to construct a time series at arbitrary values oft. – Michael E2 May 13 '23 at 20:49