Message Boards Message Boards

0
|
175 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Numerical Integration of interpolated function returning a list

Posted 9 days ago

I am encoutering a problem when trying to perform the numerical integration of a function I have obtained from interpolation that returns a list. The problem is just with NIntegrate, because Plot works well.

dataX = Table[{n, {n, 2 n}}, {n, 0, 10}];

dataF = Interpolation[dataX, InterpolationOrder -> 1];

dataFi[x_?NumericQ, i_] := dataF[x][[i]];

Plot[dataF[x], {x, 0, 10}]

NIntegrate[dataF[x], {x, 0, 10}] (*Returns NIntegrate::inum*)

NIntegrate[Table[dataFi[x, i], {i, 1, 2}], {x, 0, 10}] (*Returns result with several Part::partw warnings*)

Table[NIntegrate[dataFi[x, i], {x, 0, 10}], {i, 1, 2}] (*Returns result and one Part::partw warning*)

I think I have done this in the past with previous versions and it was working, now with 13.3 it does not. Is it a bug or is this intended? Possible workarounds?

POSTED BY: Giorgio Busoni
2 Replies

This problem goes back at least to V11. See https://mathematica.stackexchange.com/a/126361 for a couple of workarounds.

You may be thinking that the following implies NIntegrate could handle vector-valued function:

NIntegrate[{Cos[x^3], Sin[x^3]}, {x, 0, 10}]
(*  {0.776098, 0.444613}  *)

But the following shows that NIntegrate[] is threaded over the list of integrands, and each integrand is integrated separately.

Trace[
 NIntegrate[{Cos[x^3], Sin[x^3]}, {x, 0, 10}],
 TraceDepth -> 1]
(*
{NIntegrate[{Cos[x^3],Sin[x^3]},{x,0,10}],
  {NIntegrate[Cos[x^3],{x,0,10}], NIntegrate[Sin[x^3],{x,0,10}]},
  {0.776098,0.444613}}
*)

BTW, @Gianluca's Integrate in effect integrates the interpolating formulas, more or less exactly up to machine precision round off.

POSTED BY: Michael Rogers

It seems that NIntegrate does not handle vector-valued InterpolatingFunction. Strangely enough, Integrate works fine:

dataX = Table[{n, {n, 2 n}}, {n, 0, 10}];
dataF = Interpolation[dataX];
Integrate[dataF[x], {x, 0, 10}]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract