In working with interpolating functions and integration, I noticed a lot of differences between NIntegrate
and Integrate
in the case of a function applied to an interpolating function.
In order to provide a simple example, look at this output:
ifun = Interpolation[ {{0, 0}, {1, 1}, {2, 3}, {3, 4}, {4, 3}, {5, 0}}]
NIntegrate[x*ifun[x], {x, 0, 5}]
32.5694
xifun = FunctionInterpolation[x*ifun[x], {x, 0, 5}]
FunctionInterpolation::precbd: Requested precision [Infinity] is not a machine-sized real number between \$MinPrecision and \$MaxPrecision. >>
out = Integrate[xifun[x], {x, 0, 5}];
N[out]
32.591
The difference is at the second decimal place, or of the order of 0.06%. For more complicated functions (lots of data values and Bessel functions, I get errors of more than 100%).
I would like to know the reason of the error. In my real-life example I only get correct answers using the NIntegrate
method.
I know there is this other question: How to integrate functions of linearly interpolated data?
But they don't use FunctionInterpolation
and I think that there should be a simple explanation for this difference. My data is also not linearly-interpolated.