6
$\begingroup$

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

$\endgroup$
  • $\begingroup$ NIntegrate works. $\endgroup$ – george2079 Apr 13 '17 at 16:49
  • $\begingroup$ 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? $\endgroup$ – ftiaronsem Apr 13 '17 at 16:51
  • $\begingroup$ 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 $\endgroup$ – george2079 Apr 13 '17 at 17:06
  • $\begingroup$ Use FunctionInterpolation to create mytest, then you can integrate that. $\endgroup$ – Marius Ladegård Meyer Apr 13 '17 at 18:24
6
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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