Related: Integrating a functional of an InterpolatingFunction

This has been here a decade ago and I'm sure is rather outdated.

So same question: Suppose I have an InterpolatingFunction ifunc[x,y] and I wish to Integrate it with a Polynomial (FOR EXAMPLE):


Normally this does not evaluate to anything. What would be nice is to get back an InterpolatingFunction.

How would one proceed? Clearly, if InterpolatingFunction really is just a Piecewise defined polynomial, then one could split any other polynomial in the same way and have a total piecewise function which can be integrated.

But is this the only way?

EDIT: Added context.

I have a function which is made of Chebyshevs: $f(x,y)=\sum^N_{i,j}T_i(x)T_j(y)$. N is so large, that integrals involving this term become unviable:Integrate[f(x,y)polynomial,{x,0,z}]. In fact, these terms may even be used later in a similar integral, completely exploding the amount of work.

To circumvent this, I used ifun = FunctionInterpolation[f[x,y],...].

So in the end, I have Integrate[ifun(x,y)polynomial,{x,0,z}] that may be further integrated. I'd like to avoid having too long expression again.

  • $\begingroup$ Derivative[-1, 0][ifunc][x, y] x - Derivative[-2, 0][ifunc][x, y]? $\endgroup$
    – Goofy
    Jan 25 at 12:19
  • $\begingroup$ Sorry if I dont get it, but this uses the explicit form of the Integrand no? So if the polynomial was complicated, I'd need to do a lot by hand. $\endgroup$ Jan 25 at 12:25
  • $\begingroup$ See my answer.... $\endgroup$
    – Goofy
    Jan 25 at 12:47

3 Answers 3


An "exact" result instead of an approximation by FunctionInterpolation:

byparts[ifunc_, p_, x_] :=
   n = Exponent[p, x]; 
   Sum[(-1)^k  Derivative[-k - 1, 0][ifunc][x, y] D[p, {x, k}], {k, 0,

byparts[ifunc, a  x^2 + b  x + c, x]

enter image description here

If ifunc is exact, then the result is exact. If ifunc is an approximation, then the result is exact up to the error inherent in ifunc, plus minimal round-off is incurred in integrating the component polynomials in ifunc.

  • $\begingroup$ Interesting answer, however, if you do a definite integral, the amount of terms quickly explode. (Which of course does not invalidate the answer, but I kind of use interpolation functions in the first place to avoid this problem) I'll give a bit more context in an EDIT $\endgroup$ Jan 25 at 14:54

Another "exact" answer:

ifunc = Interpolation[
  Flatten[Table[{{x, y}, LCM[x, y]}, {x, 4}, {y, 4}], 1]];
Derivative[-1, 0][
   Table[Block[{x, y}, {x, y} = p; {p, ifunc[x, y] polynomial}], {p, 
     Flatten[ifunc["Grid"], 1]}]]
  ][[1, 0]] (* extracts the InterpolatingFunction *)

It will be exact on the example I chose. There are many kinds of interpolating functions. If there were a test example, I could check that it would work in the OP's use-case.

  • $\begingroup$ How would I be able to send you the coefficient list of my function that gets squared, from which I then do an interpolation function? Also, I don't know what you mean by many kinds of interpolating functions. Afaik There is only one type. $\endgroup$ Jan 25 at 14:26
  • $\begingroup$ @Confuse-ray30 Re "my function that gets squared" — I'm not sure what this means. I think that's what polynomial represents but "coefficient list" seems a completely different input. A representative working example that users can copy/paste into Mathematica would be helpful, to others as well as me, I think. — There's element mesh interpolation and structured grid interpolation in 2D and higher, maybe others. In 1D there's cubic Hermite, Chebyshev, local series, maybe others. The precision and interpolation order can make a difference, sometimes. $\endgroup$
    – Goofy
    Jan 25 at 19:23
  • $\begingroup$ I see. To be honest, I just did FunctionInterpolation of a function consisting of Chebyshevs. I don't know which Method Mathematica then used. $\endgroup$ Jan 26 at 10:17

You may combine interpolating functions using "FunctionInterpolation". Here is an example:

ifunc = Interpolation[
  Flatten[Table[{x, y, x  y}, {x, 0, 4}, {y, 0, 4}], 1]]
poly[x_, y_] = x + y^2;
f2 = FunctionInterpolation[
  ifunc[x, y]  poly[x, y], {x, 0, 4}, {y, 0, 4}]
Integrate[f2[x, y], {x, 0, 4}]

enter image description here

  • $\begingroup$ Hm... When I tested it with this: test = Interpolation[{{0, 0}, {1, 1} {2, 3}, {3, 4}, {4, 3}, {5, 0}}] and FunctionInterpolation[x*test[x], {x, 0, 5}] it gave me FunctionInterpolation::precbd: Requested precision \[Infinity] is not a machine-sized real number between $MinPrecision and $MaxPrecision. Your code works though, for some reason. $\endgroup$ Jan 25 at 12:43
  • 3
    $\begingroup$ Try interpolationwith numerical data: test = Interpolation[{{0, 0}, {1, 1} {2, 3}, {3, 4}, {4, 3}, {5, 0}} // N] $\endgroup$ Jan 25 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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