Re: Boolean Integral
- To: mathgroup at smc.vnet.net
- Subject: [mg62388] Re: Boolean Integral
- From: "Valeri Astanoff" <astanoff at yahoo.fr>
- Date: Wed, 23 Nov 2005 01:12:05 -0500 (EST)
- References: <dlupfj$nb2$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
This is the way I would do it.
(not very clever, but it works):
In[1]:=
chi[func_,y1_,y2_]:=Boole[y1<func<y2];
foo[x_]:=-BesselJ[1,x]
y1=.12; y2=.16;
x1=0; x2=20;
r1=Table[FindRoot[foo[x] == y1,{x,u}],{u,x1,x2,(x2-x1)/100}];
r2=Table[FindRoot[foo[x] == y2,{x,u}],{u,x1,x2,(x2-x1)/100}];
s1=Select[Union[r1,SameTest -> (Abs[(x/.#2)-(x/.#1)]<10^-5&)],
x1<(x/.#)<x2&];
s2=Select[Union[r2,SameTest -> (Abs[(x/.#2)-(x/.#1)]<10^-5&)],
x1<(x/.#)<x2&] ;
xx=Union[{x1},x /. s1, x /. s2,{x2}]//Sort;
Sum[ NIntegrate[chi[foo[x],y1,y2],{x,xx[[i]],xx[[i+1]]}],
{i,1,Length[xx]-1}]//Timing
Out[9]={0.485 Second, 1.33977}
hth
v.a.