# Multiply interpolating function with variable

I am always running into trouble when trying to use interpolating functions. I am trying to do:

ClearAll["Global*"]
ifun = ListInterpolation[RandomReal[1, {10, 10}], {{0, 2}, {0, 2}}];
mytest = Function[#1*Derivative[1, 0][ifun][#1, #2] ];
Integrate[mytest[x, y], {x, 0, 1}, {y, 0, 1}]


But integrate doesn't evaluate. However

Integrate[ifun[x, y], {x, 0, 1}, {y, 0, 1}]
mytest[1, 1]


works just fine. I also tried

ClearAll["Global*"]
ifun = ListInterpolation[RandomReal[1, {10, 10}], {{0, 2}, {0, 2}}];
mytest2[x_, y_] := Evaluate[x*D[ifun[x, y], {x, 1}]]
Integrate[mytest2[x, y], {x, 0, 1}, {y, 0, 1}]


But that didn't work either (integrate doesn't evaluate). I really don't understand what I am doing...

• NIntegrate works. Commented Apr 13, 2017 at 16:49
• Yes but it if the interpolating function is more complex I get a lot of warnings about slow convergence, oscillatory integrals, etc. The Random Real above is just an example. In principle Interpolating function is just a polynomial, isn't it? So one should be able to multiply it with another polynomial and integrate it exactly, or am I wrong? Commented Apr 13, 2017 at 16:51
• You are right it is possible in principle, but is seems Integrate doesnt know how to do it. You might find this useful. mathematica.stackexchange.com/q/59944/2079 Commented Apr 13, 2017 at 17:06
• Use FunctionInterpolation to create mytest, then you can integrate that. Commented Apr 13, 2017 at 18:24

One of FunctionInterpolations main purposes is to combine different expressions involving InterpolatingFunctions; from the docs:

You can use FunctionInterpolation to generate a single InterpolatingFunction object from an expression containing several such objects.

In this case we can do:

SeedRandom[0];
ifun = ListInterpolation[RandomReal[1, {10, 10}], {{0, 2}, {0, 2}}];
deriv = Derivative[1, 0][ifun];
combined = FunctionInterpolation[x*deriv[x, y], {x, 0, 2}, {y, 0, 2}];
Integrate[combined[x, y], {x, 0, 1}, {y, 0, 1}]


-0.00824225