6

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...

ftiaronsem
  • 665
  • 4
  • 13
  • NIntegrate works. – george2079 Apr 13 '17 at 16:49
  • 1
    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? – ftiaronsem Apr 13 '17 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. https://mathematica.stackexchange.com/q/59944/2079 – george2079 Apr 13 '17 at 17:06
  • Use FunctionInterpolation to create mytest, then you can integrate that. – Marius Ladegård Meyer Apr 13 '17 at 18:24

1 Answers1

6

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

Marius Ladegård Meyer
  • 6,805
  • 1
  • 17
  • 26