MathGroup Archive 1998

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

Search the Archive

Re: Need integration help!

Stefan Jeglinski wrote:
> I'm evaluating Mathematica on a friend's machine, trying to see if I can
> do this calc so I can dump another math engine I own. I have only
> Wolfram's book and my wits.
> I am calculating an integral that looks like this:
>          4
>          /
>          | T(w)/(w^2 - 5^2) dw
>          /
>         2
> It happens that T(w) is a previously defined, debugged, and well-behaved
> InterpolatingFunction over the range of integration. I am using
> NIntegrateInterpolatingFunction. The exact Mathematica coding I use is:
> NIntegrateInterpolatingFunction[T[w]/(w^2 - 5^2), {w, 1, 4}]
> This calculates a number. FYI, the result happens to be 0.0111 for my
> T[w]. All's well so far. But, as a lead-in to my punchline question, I
> am also defining a function F thusly:
> F[e_]=NIntegrateInterpolatingFunction[T[w]/(w^2 - e^2), {w, 1, 4}]
> When I define this, I get a message 'Integrand is not numerical at w =
> 2.' I'm not sure what this means. I thought it was just a warning
> reminder that the integrand could be singular if I wasn't careful, but
> I didn't worry about it since I am making sure my value of 'e' is
> always well outside of  the integrating limits (in this case, e=5). But
> now I realize this warning probably is serious and that I need to be
> more careful because
> F[5] yields 0.0027, NOT the previous 0.0111 !!!!!
> Can anyone explain the nuances of this subtlety? What is the deep
> meaning of the above warning and how can it mess me up? Am I doing
> something improperly or dumb?
> Now, if that's not enough, *here* is the -punchline- question:
> What I *really* need to do for my application is define
> F[e_]=NIntegrateInterpolatingFunction[T[w]/(w^2 - e^2), {w, 1, e-1}]
> so I can generate a list of values F[5], F[6], F[whatever]. But
> Mathematica does not like the upper limit to be anything other than a
> number, apparently. Regardless of my earlier question, how can I define
> a function whose arguments may include an integral's upper limit?
> Help! I'd like to switch to Mathematica. There's gotta be a way to do
> this.

I have not been able to reproduce your first problem - different answers
- but your other problems, messages about non numeric values and non
numeric range are innocuous here. Mathematica is saying thet it can't
fully evaluate but holds the the expression found so far until the
input is suitable. One thing that becomes evident is that more detailed
guidelines for when to use NIntegrateInterpolatingFunction instead of
NIntegrate would be useful.

I hope that this will become clearer as I work through your material
below - this will take some time. 

Load the Add-On needed

Make an InterpolatingFunction, T.

T = FunctionInterpolation[Sin[x], {x,1,6}];

First integration:

NIntegrateInterpolatingFunction[T[w]/(w^2 - 5^2), {w, 1, 4}]//Timing

{0.9 Second, -0.0414883}

It turns out to be useful to have tried ordinary NIntegrate: In[4]:=
NIntegrate[T[w]/(w^2 - 5^2), {w, 1, 4}]//Timing

{0.1 Second, -0.0414883}

Notice that in this case NINtegrate is much faster - this will explain
some later timings.

Make a functions for such integrations (I will edit the message

F1[e_]=NIntegrateInterpolatingFunction[T[w]/(w^2 - e^2), {w, 1, 4}]

>From In[5]:=
   Integrand ----------------- is not numerical at {w} = 
              1.05276 - 1. e

   Integrand ----------------- is not numerical at {w} = 
              1.05276 - 1. e

NIntegrate[-------, {w, 1, 1.052083333333333, 
            2    2
           w  - e
   1.104166666666666, 1.15625, 1.208333333333333, 
   3.916666666666666, 3.96875, 4}]

The output is NIntegrate split over the subranges where the
interpolating function, T, is known to be smooth - this is the
essential job of NIntegrateInterpolatingFunction. Mathematica cannot
evaluate further since e is not numeric. Notice that the messages are
from NIntegrate, not NIntegrateInterpolatingFunction.

Evaluate and time:

{0.866667 Second, -0.0414883}

One way of avoiding all the messages is to use delayed assignment (SetDelayed,
:=) instead of Set, = . This does not evaluate the right side - and so has
additional consequences.

F1d[e_]:=NIntegrateInterpolatingFunction[T[w]/(w^2 - e^2), {w, 1, 4}];

Now we can find what is stored about F1d:


>From In[8]:=
F1d[e_] := NIntegrateInterpolatingFunction[T[w]/(w^2 - e^2), 
   {w, 1, 4}]

This is just what we put in - NIntegrateInterpolatingFunction has not
done the range splitting.

Evaluate and time

{0.916667 Second, -0.0414883}

Just a bit longer, perhaps because of the splitting having to be done

Now for your last function with e in the integral limits. In[10]:=
F2[e_]=NIntegrateInterpolatingFunction[T[w]/(w^2 - e^2), {w, 1, e-1}];


   w = -1. + e is not a valid limit of integration.

  • Prev by Date: re help
  • Next by Date: Re: 3D Graphics Spherical Coordinates
  • Prev by thread: Need integration help!
  • Next by thread: Re: Need integration help!