MathGroup Archive 2010

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

Search the Archive

Re: Sort of nested NIntegrate

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107223] Re: [mg107176] Sort of nested NIntegrate
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Fri, 5 Feb 2010 07:14:03 -0500 (EST)
  • References: <201002050819.DAA06471@smc.vnet.net>

Hi,

you have a couple of choices. Either use NIntegrate to do both integrations
at once (the domain can
be not necessarily rectangular):

In[1]:= NIntegrate[Cos[x*Sin[t]],{t,0,1},{x,0,2}]

Out[1]= 1.6679

or define your function only on numeric values:

In[2]:= f[x_?NumericQ] := NIntegrate[Cos[x*Sin[t]], {t, 0, 1}];

In[3]:= NIntegrate[f[x], {x, 0, 2}]

Out[3]= 1.6679

Regards,
Leonid


On Fri, Feb 5, 2010 at 11:19 AM, g.resta at iit.cnr.it <g.resta at iit.cnr.it>wrote:

> I have the following little problem with a function defined by means of
> NIntegrate.
> My function is much more complicated, but the following example suffices.
>
> Suppose I've defined a function in this way
>
> fu[x_] := NIntegrate[ Cos[ x * Sin[t] ],  {t, 0, 1}];
>
> Mathematica can easily compute numerically and plot the function fu.
>
> Now, I want to use the function fu in another NIntegrate, say
>
> NIntegrate[ fu[x]^2, {x,0,2}]
>
> I hoped that was innocuous (maybe slow, since each point of fu require
> another
> automatic quadrature) but I got instead this error:
> NIntegrate::inumr: The integrand Cos[x Sin[t]] has evaluated to non-
> numerical values for all sampling points in the region with boundaries
> {{0,1}}.
>
> I also got a number which looks like the right value, but I'm afraid
> to trust it because
> I do not fully understand the error message. It seems like Mathematica
> is trying to do
> something symbolic with the guts of fu, even if fu is defined by means
> of NIntegrate.
> But I'm probably wrong.
>
> Surely I'm missing something. Can anybody show me the light?
> (that is, the right way to perform similar computations, maybe the
> right option to pass along?)
>
> thank you very much,
> giovanni
>
>
>
>



  • Prev by Date: Re: Sort of nested NIntegrate
  • Next by Date: a harmless notebook crashes Windows 7: who else had it?
  • Previous by thread: Re: Sort of nested NIntegrate
  • Next by thread: Extra Data and Data structures