From: Nils Tobias on
Thanks Stefan,

I thought there might be way to redefine this property. Anyway in my case it somehow makes sense because I could define my equation also without the division... which I probably should do.

But for now I just calculate it like you suggested with a simple M-file called wrongdivision.m

Thanks!

"Stefan" <nospam(a)yahoo.com> wrote in message <i2uabn$mfp$1(a)fred.mathworks.com>...
>
> You should be careful with such interpretations. But:
>
> a=0;
> b=0;
>
> c=a/b;
>
> if(isnan(c) && (a==0) && (b==0))
> c=0;
> end
>
> Something like this perhaps.
>
> Regards,
> Stefan
>
>
> "Nils Tobias " <nils.kraemer(a)uni-ulm.de> wrote in message <i2u63a$p3u$1(a)fred.mathworks.com>...
> > Hi Matlab community,
> >
> > Matlab normaly treats division by zero like this:
> > 1) 0/0 = NaN
> > 2) 1/0 = Inf
> >
> > Is there a way to redefine these definitions. My problem is that I want - only in a special case (some sort of indicator function) - that 0/0 = 0. I know it's incorrect but maybe there's some way of doing it.
> >
> > Thanks a lot
> > -NT
From: Peter Perkins on
On 7/30/2010 5:30 AM, Nils Tobias wrote:
> Is there a way to redefine these definitions. My problem is that I want
> - only in a special case (some sort of indicator function) - that 0/0 =
> 0. I know it's incorrect but maybe there's some way of doing it.

It isn't incorrect if you know that in whatever limit you're talking
about, the expression that leads to NaN has the limit zero. If you have
this

x = 0;
y = x.*log(x);

and x is always a non-negative real (a probability, for example), then
certainly you'd want to be able to get 0 for y. One way to do that is
to define a function

function y = xlogx(x)
% XLOGX x*log(x) for non-negative x
y = x.*log(x);
y(x==0) = 0;

and then use that in place of x.*log(x). It assumes that the input is
real and non-negative (and should probably error out if not).

The NaN you get from 0/0 just indicates that there is no way for the
division to know what the correct limit is. If you know it, then you
can impose it.

Hope this helps.