Re: Re: Integrate with If
- To: mathgroup at smc.vnet.net
- Subject: [mg22511] Re: [mg22361] Re: [mg22180] Integrate with If
- From: Hartmut Wolf <hwolf at debis.com>
- Date: Sun, 5 Mar 2000 00:24:50 -0500 (EST)
- Organization: debis Systemhaus
- References: <200002170624.BAA04409@smc.vnet.net> <88jt51$9lf@smc.vnet.net> <200002260214.VAA05868@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Bergervoet J.R.M. schrieb: > > In <88jt51$9lf at smc.vnet.net> Hartmut Wolf <hwolf at debis.com> writes: > > >> Why does > >> > >> Integrate[If[Sin[t] > 0, 1, 0] , {t, -Pi, Pi}] > >> > > >Integrate doesn't work with If, use UnitStep instead. So both > > >In[17]:= Plot[UnitStep[t], {t, -Pi, Pi}] > >Out[17]= Graphics[] > > >In[18]:= Integrate[UnitStep[t], {t, -Pi, Pi}] > >Out[18]= Pi > > >do well. > > But this functionallity (in order to generalize to functions other than > Sin[]) would require: > > Integrate[UnitStep[Sin[t]], {t,-Pi, Pi}] > > and that still gives 0 (incorrect!). It does work with jump-point 0: > > Integrate[UnitStep[Sin[t]], {t,-Pi, 0, Pi}] > > which correctly gives Pi. > Dear Jos, let's see what is peculiar to that "jump-point". If I do these Integrals In[1]:= Integrate[UnitStep[Sin[t]], {t, -7.5, -0.1}] Out[1]= \[Pi] In[2]:= Integrate[UnitStep[Sin[t]], {t, -0.1, 3.5}] Out[2]= \[Pi] they both come out right, however if we join the range of intgration In[3]:= Integrate[UnitStep[Sin[t]], {t, -7.5, 3.5}] Out[3]= 10.6416 In[4]:= % == 7.5 + Pi Out[4]= True ...we get that peculiar result. Now inclusion of that jump-point doesn't help In[7]:= Integrate[UnitStep[Sin[t]], {t, -7.5, 0, 3.5}] Out[7]= 13.7832 In[8]:= % - 7.5 == 2 Pi Out[8]= True Is that a little bit more correct? possibly. Let's try other "magic points" In[9]:= Integrate[UnitStep[Sin[t]], {t, -7.5, -Pi, 3.5}] Out[9]= \[Pi] In[10]:= Integrate[UnitStep[Sin[t]], {t, -7.5, -Pi/2, 3.5}] Out[10]= 2 \[Pi] ...so we get at least one correct result. So how do we have to make up the integration range in general? After some trial and error I found the following fix: fixIterator3[{x_Symbol, a_?NumericQ, b_?NumericQ}] /; OrderedQ[{a, b}] := Join[{x, a}, (4 Range[Ceiling[a /(2Pi) + 1/4], Floor[b /(2Pi) + 1/4]] -1) Pi/2, {b}] fixIterator3[{x_Symbol, a_?NumericQ, b_?NumericQ}] /; OrderedQ[{b, a}] := Join[{x, a}, (4 Range[Floor[a /(2Pi) + 1/4], Ceiling[b /(2Pi) + 1/4], -1] -1) Pi/2, {b}] Try it with Plot[Integrate[UnitStep[Sin[t]], {t, 0, b} // fixIterator3], {b, -8 Pi, 8 Pi}] and compare that with Plot[Integrate[UnitStep[Sin[t]], {t, 0, b}], {b, -8 Pi, 8 Pi}] !!! (Perhaps it's interesting to look at a Plot3D with both, lower and upper integration bounds varyiing -- shure, at some gross resolution) However this doesn't set up a general rule as to deal with similar cases. I simply have none. Integrate appears as a delicate lady who charms those being courteous, yet she simply won't accept a rude request "hey, solve that!" Some introspection might help also: what would you do, you had the task of creating "Integrate"? You certainly would resort to a functional, "algebraic" calculus -- we are doing computer algebra -- which would include algebraic functions, all you can reach of the special functions, UnitStep, of course, and DiracDelta. You would have to deal with inverse functions, even when the inverse is not unique, with Riemannian sheets and branch cuts,... You would have a bunch of rewrite rules and a sophisticated strategy as how to apply them. It's horribly complicated. Clearly this excludes expressions containing If, Which other things which are not part of that mathematical calculus you start with. This was the case of Johan Berglind's posting. Your case is somewhat different. However that Integrate[UnitStep[Sin[t]], {t, ...}] would be difficult, can be seen when we substitute for the integration variable: In[61]:= sol = Integrate[UnitStep[u](1 - u^2)^-(1/2), u] Out[61]= ArcSin[u] UnitStep[u] And then Subtract @@ (sol /. {{u -> b}, {u -> a}}) gives a correct answer between -Pi/2 <= a, b <= Pi/2. The problem here of course comes from the inversion of the Sin function (and additionally, introduced by myself) from the adequate sign for the square root. If you deal well with the latter you'll get a correct answer for -Pi/2 <= a, b <= 3 Pi/2. Certainly I don't know about the internal mechanism of Integrate, but this observation was the base of my guess for that fixIterator3 above. Now, what would happen, if we tried In[74]:= Integrate[UnitStep[BesselJ[0, t]], {t, -10., 10.}] Well, simply nothing. So the case here is that the "functional calculus" is just not implemented as far as we wish. In version 3 this was in a seperate package Calculus`DiracDelta`, a glimpse into it might reveal something. This doesn't mean we cannot proceed further. A possibility could be to use In[79]:= FindRoot[BesselJ[0, t] == 0, {t, #}] & /@ (Pi Range[5]) to get at the zeroes, use them for a definition with UnitStep, and with that integrate any function effectively over the ranges with positive BesselJ[0,t]. (This may be preferable to separate integration over individual ranges when the bounds are parametric and ranges might become overlapping) Kind regards, Hartmut