Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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}]
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}];

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.

share|improve this question
up vote 2 down vote accepted

Give this a whirl:

ifun = Interpolation[{{0, 0}, {1, 1}, {2, 3}, {3, 4}, {4, 3}, {5, 0}}];
out1 = NIntegrate[x*ifun[x], {x, 0, 5}];

xifun = FunctionInterpolation[x*ifun[x], {x, 0, 5, .01}];
out2 = Integrate[xifun[x], {x, 0, 5}];

Row[{out1, N[out2]}, "    "]

(*  32.5694    32.5694  *)
share|improve this answer
This third argument appears with color red in my Mathematica 9 version. That means that it shouldn't go there. I also didn't find it in the documentation. I tried it anyway and it indeed works for the more complicated case! What is it, the precision? – Santi Mar 4 '14 at 13:04
@Santi. The syntax highlighter isn't infalible. It sometimes rejects a form that works -- maybe because the the function involved has been recently changed and the syntax editor didn't get updated with the change. I've encountered this with functions other than FunctionInterpolation. Go with what works. – m_goldberg Mar 4 '14 at 13:43
@Santi Evaluation of xifun["Grid"] // Differences reveals that the third argument is just the sampling step. – Alexey Popkov Mar 4 '14 at 16:34
@Santi: Sorry for delay responding, needed sleep! As Alexy said, it is sample step - I discovered this some time ago, figured it was common knowledge, sorry for not explicitly defining it and causing confusion. – ciao Mar 4 '14 at 21:16
FunctionInterpolation::precbd error will be surpressed if one changes the range to be machine precision number i.e. {x,0,5} to be {x,0.,5} (@Santi). Very odd. – luyuwuli Mar 22 at 11:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.