MathGroup Archive 2005

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

Search the Archive

Re: Boolean Integral

  • To: mathgroup at smc.vnet.net
  • Subject: [mg62432] Re: [mg62357] Boolean Integral
  • From: "Carl K. Woll" <carlw at wolfram.com>
  • Date: Thu, 24 Nov 2005 06:33:30 -0500 (EST)
  • References: <200511220941.EAA23628@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Brambilla Roberto Luigi (CESI-PGE) wrote:
> Hi,
>  
> I have defined the following support function:
> 
> chi[func_,y1_,y2_]:=Boole[yi<func<y2]
> 
> that gives 1 if yi<func<y2 and 0 otherwise. It works well with Plot :
> 
> (*example*)	
> foo[x_]:=-BesselJ[1,x]
> y1=.12;
> y2=.16;
> Plot[{foo[x],chi[foo[x]],y1,y2],y1,y2},{x,0,20},
> PlotRange->All,PlotStyle->{Black,Red,Blue,Blue}]
> 
> but if I want to *measure* the sum of intervals where y1<foo<y2, the answer is wrong:  the integral
> 
> NIntegrate[chi[foo[x],y1,y2],{x,0,20}]
> 
> often gives 0 since x-sample points (Gauss points) of a numerical method may fall into intervals where chi=0. 
> If I use Method->MonteCarlo the results is rather slow (10 sec.) and change a little bit at every execution
> 
> NIntegrate[chi[foo[x],y1,y2],{x,0,20},Method->MonteCarlo]
> 1.3668
> 
> There are other NIntegrate settings to obtain the wright result more quicly?
> (I would like to avoid to use FindRoot and to fragment the integral etc...)
> 
> Any help well accepted.
> Thank You.
> Rob.
> 

Anton already answered your question.

I wanted to point out that if it is easy to find the locations where 
foo[x] equals y1 and y2, then inserting these points into the 
integration contour would provide an accurate answer quickly. For your 
particular example, it is very easy to find out where foo[x] equals y1 
and y2 by using the package BesselZeros:

Needs["NumericalMath`BesselZeros`"]

In[31]:=
end1=x/.FindRoot[-BesselJ[1,x]==.12,{x,#}]&/@BesselJZeros[1,6]
end2=x/.FindRoot[-BesselJ[1,x]==.16,{x,#}]&/@BesselJZeros[1,6]

Out[31]=
{4.14659,6.61696,10.6883,12.7561,17.1432,18.9029}

Out[32]=
{4.26343,6.47821,10.898,12.5337,17.4646,18.5722}

Construct the integration path:

In[34]:=
path=Join[{x,0},Sort[Join[end1,end2]],{20}]

Out[34]=
{x,0,4.14659,4.26343,6.47821,6.61696,10.6883,10.898,12.5337,12.7561,17.1432,\
17.4646,18.5722,18.9029,20}

Evaluate the integral. Note that we don't need to "fragment" the integral:

In[37]:=
NIntegrate[chi[-BesselJ[1,x],.12,.16],Evaluate[path]]//Timing

Out[37]=
{0.047 Second,1.33977}

Of course, if the end points are known, it is simpler to just add them up:

In[38]:=
Total[Abs[end1-end2]]

Out[38]=
1.33977

> 
> 
> 
> 
> 
> 
> CESI SpA ha adottato il Modello Organizzativo ai sensi del D.Lgs.231/2001, in forza del quale l'assunzione di obbligazioni da parte della Società avviene con firma di un procuratore, munito di idonei poteri.
> CESI adopts a Compliance Programme under the Italian Law (D.Lgs.231/2001). According to this CESI Compliance Programme, any commitment of CESI is taken by the signature of one Representative granted by a proper Power of Attorney.
> 
> Le informazioni contenute in questo messaggio di posta elettronica sono riservate e confidenziali e ne e' vietata la diffusione in qualsiasi modo o forma. Qualora Lei non fosse la persona destinataria del presente messaggio,   La invitiamo a non diffonderlo e ad eliminarlo, dandone gentilmente comunicazione al mittente.
> The information included in this e-mail and any attachments are confidential and may also be privileged. If you are not the correct recipient, you are kindly requested to notify the sender immediately, to cancel it and not to disclose the contents to any other person.

Carl Woll
Wolfram Research


  • References:
    • Boolean Integral
      • From: "Brambilla Roberto Luigi (CESI-PGE)" <RLBRAMBILLA@cesi.it>
  • Prev by Date: Re: Re: How to View Mathematica and Hardcopy Books
  • Next by Date: Re: Time needed for calculation
  • Previous by thread: Boolean Integral
  • Next by thread: Re: Boolean Integral