# NIntegrate of a vector-valued InterpolatingFunction gives "not numerical"

If I construct a vector-valued InterpolatingFunction, say with

f = Interpolation[{{0, {1,1}}, {1, {0,0}}, {2, {0,1}}, {3, {1,0}}}]


plotting the result works just fine. For example,

ParametricPlot[f[t], {t, 0, 3}]


draws a letter "alpha" in the plane. And, as Feyre pointed out, calling Integrate also works fine, with

Integrate[f[t], {t, 0, 3}]


returning {3/4, 3/2}. But Integrate can't deal with more complicated situations, returning unevaluated for even such simple variants as

Integrate[2 f[t], {t, 0, 3}]


More complicated cases can be handled numerically with NIntegrate, as long as the thing being integrated is a scalar. For example,

NIntegrate[f[t].f[t], {t, 0, 3}]


returns 1.78214. But if I try to NIntegrate a vector-valued InterpolatingFunction, even just:

NIntegrate[f[t], {t, 0, 3}]


version 10.0.2 of Mathematica gives me the error message:

NIntegrate::inum: Integrand
InterpolatingFunction[{{0,3}},{5,3,0,{4},{4},0,0,0,0,Automatic,
{},{},False},{{0,1,2,3}},
{{{0,0}},{{1,1}},{{1,0}},{{0,1}}},{Automatic}][t]
is not numerical at {t} = {0.00795732}. >>


In a case too complicated for Integrate, is there some way that I can convince NIntegrate to work, component by component, over such a vector?

• There's always going to be a technique to find what you want, if everything else fails, just use Table[] and Total[] Sep 14 '16 at 22:15

You can use Indexed to access the components separately:

NIntegrate[Indexed[f[t], 1], {t, 0, 3}]
NIntegrate[Indexed[f[t], 2], {t, 0, 3}]
(*
0.75
1.5
*)


Integrate will antidifferentiate an InterpolatingFunction. You can then subtract its values at the end points.

af = Head@Integrate[f[t], t];
af[3] - af[0]
(*  {3/4, 3/2}  *)


You can also write your own integration rule to plug into NIntegrate, but that takes a little work.

You can use NDSolve to integrate your interpolating function:

f = Interpolation[{{0,{1,1}},{1,{0,0}},{2,{0,1}},{3,{1,0}}}];

NDSolveValue[{y'[x] == f[x], y[0] == {0, 0}}, y[3], {x, 0, 3}]


{0.75, 1.5}

Here is a more complicated integrand:

NDSolveValue[{y'[x] == f[x]^2 Sin[x], y[0] == {0, 0}}, y[3], {x, 0, 3}]


{0.148276, 0.887794}