Discussion:
indicator function, characteristic function
(too old to reply)
Bart Vandewoestyne
2006-09-12 11:26:17 UTC
Permalink
Does Maple have a standard command for the indicator function
(characteristic function)? For example in 2 dimensions,
every point inside the rectangle (-infty..a, -infty..b)
should give a function value of 0 and everything outside this rectangle
should give a 1.

I am currently doing it like this:

ind := (x, y, a, b) -> Heaviside(x-a)*Heaviside(y-b);

Is this the correct Maple-way to do this, or would there be a
better way or a standard Maple command?

Thanks,
Bart
--
"Share what you know. Learn what you don't."
Robert Israel
2006-09-12 22:16:08 UTC
Permalink
Post by Bart Vandewoestyne
Does Maple have a standard command for the indicator function
(characteristic function)? For example in 2 dimensions,
every point inside the rectangle (-infty..a, -infty..b)
should give a function value of 0 and everything outside this rectangle
should give a 1.
ind := (x, y, a, b) -> Heaviside(x-a)*Heaviside(y-b);
Is this the correct Maple-way to do this, or would there be a
better way or a standard Maple command?
That's wrong. It will produce undefined if x = a or y = b,
otherwise 0 if x < a _or_ y < b, and 1 if x > a and y > b.
The behaviour when x = a or y = b, resulting from Heaviside(0)
being undefined, can be changed: see the help page ?Heaviside.

You might try piecewise(x < a and y < b, 0, 1).

Robert Israel ***@math.ubc.ca
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia Vancouver, BC, Canada
Bart Vandewoestyne
2006-09-13 07:22:54 UTC
Permalink
Post by Robert Israel
Post by Bart Vandewoestyne
ind := (x, y, a, b) -> Heaviside(x-a)*Heaviside(y-b);
Is this the correct Maple-way to do this, or would there be a
better way or a standard Maple command?
That's wrong. It will produce undefined if x = a or y = b,
otherwise 0 if x < a _or_ y < b, and 1 if x > a and y > b.
The behaviour when x = a or y = b, resulting from Heaviside(0)
being undefined, can be changed: see the help page ?Heaviside.
Whoops! You are right! I guess this is what happens if I stare
at something for too long ;-)
Post by Robert Israel
You might try piecewise(x < a and y < b, 0, 1).
Thanks. I was also mis-stating what I needed: my indicator function should
return 1 if x<=a and y<=b, so I'm now using

ind := (x, y, a, b) -> piecewise(x <= a and y <= b, 1, 0);

Thanks you for spotting my mistake and correcting it!
Bart
--
"Share what you know. Learn what you don't."
Bart Vandewoestyne
2006-09-13 08:29:08 UTC
Permalink
Post by Bart Vandewoestyne
Thanks. I was also mis-stating what I needed: my indicator function should
return 1 if x<=a and y<=b, so I'm now using
ind := (x, y, a, b) -> piecewise(x <= a and y <= b, 1, 0);
And whoops again... I was again misstating what I actually need.

For your suggestion, the indicator function becomes 1 as soon
as x>=a OR y>=b. What I need is that the indicator function is 1
as soon as x>=a AND y>=b (so the componentwise comparison of the
vectors). I get this with

ind := (x, y, a, b) -> piecewise(x >= a and y >= b, 1, 0):

Notice the subtle difference between the two... and I guess my
proposal is what actually best fits my needs.

Thanks for letting me gain insight into this!
Bart
--
"Share what you know. Learn what you don't."
Loading...