MathGroup Archive 1993

[Date Index] [Thread Index] [Author Index]

Search the Archive

InterpolatingFunction's and NIntegrate

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: InterpolatingFunction's and NIntegrate
  • From: TDR at vaxc.cc.monash.edu.au
  • Date: 01 Jul 1993 19:38:05 +1100

Dear Mathgroup,

> > After all D[] knows how to handle InterpolatingFunction's, so why
> > not NIntegrate[] and Integrate[] too?
>But ND[ ] does not do anything special with InterpolatingFunction[ ]s.  The
>point is well taken that Integrate[ ] should be able to undo anything that
>D[ ] does, but I disagree that NIntegrate[ ] should do symbolic computation:
>everytime we make NIntegrate[ ] "smarter" the overhead gets a little slower
>and users wonder why something as trivial as NIntegrate[x^2, {x, 2, 5}]
>takes so long.  The "N" in NIntegrate means that the algorithm is numerical.
One can make NIntegrate[ ] "smarter" *without* slowing it down:
  Unprotect[NIntegrate];
  NIntegrate[f_InterpolatingFunction,region__List, opts___] :=
       integrateInterpolatingFunction[f,region,opts];
  Protect[NIntegrate];
This doesn't slow down a computation like NIntegrate[x, {x, 2, 5}]
any noticeable amount, as far as my timings show:
  Do[ NIntegrate[x, {x, 2, 5}], {100} ]//Timing
takes just as long before and after the above definition.

[Note there is a bug in Mma2.1 which causes NIntegrate[x^2, {x, 2, 5}]
 with x *squared* to take progressively longer each time it is called.
 So I didn't use that for my timings above. The bug is not present in Mma2.2]

The only trick now would be to write the integrateInterpolatingFunction[]
code mentioned above. For 1-D regions that cover the whole interval of the
InterpolatingFunction then
  integrateInterpolatingFunction[_[{xmin_,xmax_},table_],{_,xmin_,xmax_}] :=
          Plus @@ Map[(#[[1]]-#[[2]])*#[[3,1]]&, table]
is *roughly* the integral (I don't know the internal details of exactly what
an InterpolatingFunction table contains, so I can't write a better routine).
Sub-intervals and higher order approximations would be harder, but not
impossible. Multi-dimensional problems would be a lot trickier though.

Terry Robb






  • Prev by Date: [no subject]
  • Next by Date: Integrate[] and InterpolatingFunction's
  • Previous by thread: [no subject]
  • Next by thread: Integrate[] and InterpolatingFunction's