Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

difference between HeavisidePi and UnitBox

121 views
Skip to first unread message

Anatoly

unread,
May 29, 2009, 8:56:51 PM5/29/09
to
I am a very new user, and am not quite clear on the difference between
general (HeavisidePi) and numerical (UnitBox, or piecewise) functions.

When I try to create a 5-bar pattern using one of these and apply a
FourierTransform, I have varying degrees of success...

With HeavisidePi I can create an infinite series of them and
FourierTransform has no problems, but it doesn't like modifying the
argument as in HeavisidePi(x/w)

With UnitBox I have the opposite issue.

Is there a clear explanation on the difference between the two groups
of functions, and when I should use which?

Jens-Peer Kuska

unread,
May 31, 2009, 6:33:02 AM5/31/09
to
Hi,

what happens at x->1/2 and x->-1/2 with HeavisidePi[] and UnitBox[] ?

For distributions like HeavisidePi[] that are used
inside of an integral the single
point does not matter. For functions like UnitBox[] it may be important.

Regards
Jens

Anatoly

unread,
Jun 2, 2009, 6:38:18 AM6/2/09
to
I understand that it doesn't matter. There's even some discussion
here about it http://mathworld.wolfram.com/RectangleFunction.html

My question is regarding "The piecewise version of the rectangle
function is implemented in Mathematica as UnitBox[x], while the
generalized function version is implemented as HeavisidePi[x]."

why do we need both? I find the integral transforms (I use mostly
FourierTransform) actually work much better with the piecewise UnitBox
for 5-bar patterns that I like to use.

Does anyone have a thorough explanation of when generalized functions
are better than piecewise and vice versa?

-Anatoly

On May 31, 6:33 pm, Jens-Peer Kuska <ku...@informatik.uni-leipzig.de>
wrote:

Andrzej Kozlowski

unread,
Jun 3, 2009, 1:11:13 AM6/3/09
to
It depends on your purpose. For some simple purposes they are
equivalent but there is a huge difference when you try to do calculus
with them. You can perform most natural operations such as
differentiation or integration on generalized functions:

D[HeavisidePi[x], x]
2*DiracDelta[2*x + 1] - 2*DiracDelta[2*x - 1]

which is a well behaved generalized function while

D[UnitBox[x], x]

Piecewise[{{Indeterminate, x == 1/2 || x == -(1/2)}}, 0]

is the zero function with two undefined values at 1/2 and -1/2,
basically a useless object. So, for example:

Integrate[D[HeavisidePi[x], x], {x, -Infinity, 0}]
1

while naturally

Integrate[D[UnitBox[x], x], {x, -Infinity, 0}]
0

I came up with these examples just off hand so they may look a bit
artificial but it is easy to find ones that arise in serious problems.

Andrzej Kozlowski

On 2 Jun 2009, at 19:41, Anatoly wrote:

> I understand that it doesn't matter. There's even some discussion
> here about it http://mathworld.wolfram.com/RectangleFunction.html
>
> My question is regarding "The piecewise version of the rectangle
> function is implemented in Mathematica as UnitBox[x], while the
> generalized function version is implemented as HeavisidePi[x]."
>
> why do we need both? I find the integral transforms (I use mostly
> FourierTransform) actually work much better with the piecewise UnitBox
> for 5-bar patterns that I like to use.
>
> Does anyone have a thorough explanation of when generalized functions
> are better than piecewise and vice versa?
>
> -Anatoly
>
> On May 31, 6:33 pm, Jens-Peer Kuska <ku...@informatik.uni-leipzig.de>
> wrote:

John Doty

unread,
Jun 5, 2009, 4:13:30 PM6/5/09
to
Andrzej,

I agree with what you say here, but as a user of this functionality let
me amplify a bit.

Andrzej Kozlowski wrote:
> It depends on your purpose. For some simple purposes they are
> equivalent but there is a huge difference when you try to do calculus
> with them.

The basic issue is that "function", "derivative", and "integral" mean
different things in different mathematical contexts. For the benefit of
those who haven't encountered this, start at page 255 of:

http://books.google.com/books?id=lMdz84dWNnAC&pg=PA262&lpg=PA262&dq=davis+hersh+fourier&source=bl&ots=Bq4ZMnH4w_&sig=kzqcZZnwUT3gFovNNRHRgC3m2j4&hl=en&ei=LdsmSv29PILyMsKt8PoC&sa=X&oi=book_result&ct=result&resnum=1#PPA255,M1

for a fine overview of these issues.

> You can perform most natural operations such as
> differentiation or integration on generalized functions:
>
> D[HeavisidePi[x], x]
> 2*DiracDelta[2*x + 1] - 2*DiracDelta[2*x - 1]
>
> which is a well behaved generalized function while
>
> D[UnitBox[x], x]
>
> Piecewise[{{Indeterminate, x == 1/2 || x == -(1/2)}}, 0]
>
> is the zero function with two undefined values at 1/2 and -1/2,
> basically a useless object.

UnitBox has the unfortunate property that it doesn't have derivatives at
the important points. On the other side, HeavisideTheta isn't numeric at
those points, so it would be troublesome in numerical analysis. Which
one you should choose depends on what you're going to do with them.

Now, this isn't really much of a problem when using the math to solve an
scientific or engineering problem by hand: the physical nature of the
problem determines the interpretation of the mathematical symbols. Most
scientists and engineers aren't even aware of the issues here, and those
of us who are rarely worry about them when scribbling on the back of the
envelope. But Mathematica only sees the symbols, not the reality (if
any) behind them.


> So, for example:
>
> Integrate[D[HeavisidePi[x], x], {x, -Infinity, 0}]
> 1
>
> while naturally
>
> Integrate[D[UnitBox[x], x], {x, -Infinity, 0}]
> 0
>
> I came up with these examples just off hand so they may look a bit
> artificial but it is easy to find ones that arise in serious problems.

Not so artificial when you realize that Mathematica is likely to
evaluate such expressions as it breaks down more realistic problems.

I suspect this is exactly the kind of thing behind the difficulties
Mathematica used to have when given calculations that required
generalized functions:

http://forums.wolfram.com/mathgroup/archive/2000/Apr/msg00043.html

In the early days, Wolfram apparently believed that these issues could
be finessed by heuristics similar to the way we do applied math by hand.
So, the only explicit generalized function was DiracDelta, and
UnitStep's treatment depended on the undocumented heuristics. That
didn't work very well.

In recent versions, since the introduction of the distinction between
the Heaviside generalized functions and their numerical counterparts,
Mathematica's behavior in this area has been much better.

For me, the main application here is in analyzing "noises", such as
"white" and "flicker" noise:

http://www.nr.com/whp/Flicker_Noise_1978.pdf

For some purposes here, it's very handy to do symbolic calculations
using generalized functions, rather than numerical simulations.

>
> Andrzej Kozlowski
>
> On 2 Jun 2009, at 19:41, Anatoly wrote:
>
>> I understand that it doesn't matter. There's even some discussion
>> here about it http://mathworld.wolfram.com/RectangleFunction.html
>>
>> My question is regarding "The piecewise version of the rectangle
>> function is implemented in Mathematica as UnitBox[x], while the
>> generalized function version is implemented as HeavisidePi[x]."
>>
>> why do we need both? I find the integral transforms (I use mostly
>> FourierTransform) actually work much better with the piecewise UnitBox
>> for 5-bar patterns that I like to use.
>>
>> Does anyone have a thorough explanation of when generalized functions
>> are better than piecewise and vice versa?

> ...

--
John Doty, Noqsi Aerospace, Ltd.
http://www.noqsi.com/
--
The axiomatic method of mathematics is one of the great achievements of
our culture. However, it is only a method. Whereas the facts of
mathematics once discovered will never change, the method by which these
facts are verified has changed many times in the past, and it would be
foolhardy to expect that changes will not occur again at some future
date. - Gian-Carlo Rota

Anatoly

unread,
Jun 10, 2009, 5:35:03 AM6/10/09
to
Great, thanks for the Davis link, I will definitely try to follow up.

My typical application has been a 4F imaging system -- FourierTransform
[rect[x]], then multiply by the pupil function, another rect, then
InverseFourierTransform back into space domain.

I've tried using both HeavisidePi and the UnitBox to represent the
rect, both seem to have problems

I start having severe problems when I use multiple scaled
HeavisidePi. As a matter of fact, as soon as I shift and scale it,
FourierTransform cannot calculate a result.

With the UnitBox as the object, the results are a bit better, but then
I cannot use a sum expression to represent the 5-bar pattern, I have
to specify them explicitly. Not a big deal, and in the end things
seem to work out.

That is until I add an off-axis source, or defocus into the system.
With an off-axis source the input is UnitBox[x] E^(I x s) -- and here
the most curious thing happens. In this form everything is fine, but
when I use UnitBox[x] E^(-I x s) I get two extra DiracDeltas in the
FourierTransform with different signs. But I am side-tracked.

For this kind of application, FourierTransform[UnitBox], multiply by
UnitBox, InverseFourierTransform, am I using the right function?
Should I spend more time with HeavisidePi?

Thanks again for the discussion guys, I feel slightly less lost

0 new messages