NIntegrate of a vector-valued InterpolatingFunction gives "not numerical"
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}