# Integrate InterpolatingFunction times polynomial

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):

Integrate[ifunc[x,y]x,{x,0,z}]


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?

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.

• Derivative[-1, 0][ifunc][x, y] x - Derivative[-2, 0][ifunc][x, y]? Jan 25 at 12:19
• 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. Jan 25 at 12:25
• See my answer.... Jan 25 at 12:47

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

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

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


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.

• 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 Jan 25 at 14:54

ifunc = Interpolation[
Flatten[Table[{{x, y}, LCM[x, y]}, {x, 4}, {y, 4}], 1]];
Derivative[-1, 0][
Interpolation[
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.

• 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. Jan 25 at 14:26
• @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. Jan 25 at 19:23
• I see. To be honest, I just did FunctionInterpolation of a function consisting of Chebyshevs. I don't know which Method Mathematica then used. 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}]


• 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. Jan 25 at 12:43
• Try interpolationwith numerical data: test = Interpolation[{{0, 0}, {1, 1} {2, 3}, {3, 4}, {4, 3}, {5, 0}} // N]  Jan 25 at 15:11