octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: No isimag() curioso


From: Michael D Godfrey
Subject: Re: No isimag() curioso
Date: Sat, 08 Sep 2012 00:05:54 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120828 Thunderbird/15.0

On 09/07/2012 05:30 PM, Daniel J Sebald wrote:
In working with the fftfilt() routine and wanting to know if the inputs were purely imaginary I wondered why there is no such thing as isimag().  It seems as though it would be as useful as or more useful than iscomplex().

Here's the thing: iscomplex() appears to be simply the complement of isreal(), unless I'm missing a more sophisticated use of syntax:

octave:5> x = 1
x =  1
octave:6> [isreal(x) iscomplex(x)]
ans =

   1   0

octave:7> x = i
x =  0 + 1i
octave:8> [isreal(x) iscomplex(x)]
ans =

   0   1

octave:9> x = 1+i
x =  1 + 1i
octave:10> [isreal(x) iscomplex(x)]
ans =

   0   1

octave:11>

I ask, What's the point of having a function that is simply !isreal()? On the other hand isimag(), which is equivalent to "all (real (x) == 0)) && !isreal (x)", would be a nice shorthand.

Just an observation.  Usually duplication of function (or its complement) is weeded out of programming languages.

Dan
I also recently noticed some quirks with complex:
x = 1 + 0i   is treated as real and not complex.
but
x = 0 + 1i  is treated as imag and complex.

But, this is consistent with Matlab.  However, Matlab has no iscomplex and also
differs in its example for help isreal.  There, Matlab gives an example:
       x = magic(3);
       y = complex(x);

which gives:
>> y

y =

     8     1     6
     3     5     7
     4     9     2
>> isreal(y)

ans =

     0
but, ~isreal(y) gives:
ans =

     1

The text in the help messages says that
isreal(y) returns
    false, because COMPLEX returns y with an all zero imaginary
    part.
-------------------------------------------
but Octave gives:

y =

   8 + 0i   1 + 0i   6 + 0i
   3 + 0i   5 + 0i   7 + 0i
   4 + 0i   9 + 0i   2 + 0i

and:
octave:21> isreal(y)
ans = 0
and:
octave:29> ~isreal(y)
ans =  1

The only difference is in the display of y.
This hardly qualifies as a bug, but does add a bit
to the confusion.  Some people would imagine
that real and imaginary would be treated "symmetrically."

So far I do not see much point in making a change.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]