<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264608</link>
    <title>MATLAB Central Newsreader - i &lt;= 0 ??</title>
    <description>Feed for thread: i &lt;= 0 ??</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 30 Oct 2009 20:55:18 -0400</pubDate>
      <title>i &lt;= 0 ??</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264608#691086</link>
      <author>Muhammad </author>
      <description>Complex number are ordered in matlab. For the imaginary unit, i, for example, I get&lt;br&gt;
? disp(i &amp;lt; 0 | i == 0)&lt;br&gt;
ans =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&lt;br&gt;
This may be consistent behavior. But it is certainly inconsistent with the following result:&lt;br&gt;
? disp (i &amp;lt;= 0)&lt;br&gt;
ans =&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1</description>
    </item>
    <item>
      <pubDate>Fri, 30 Oct 2009 21:05:44 -0400</pubDate>
      <title>Re: i &lt;</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264608#691088</link>
      <author>Nathan</author>
      <description>On Oct 30, 1:55&#160;pm, &quot;Muhammad &quot; &amp;lt;muh...@shaw.ca&amp;gt; wrote:&lt;br&gt;
&amp;gt; Complex number are ordered in matlab. For the imaginary unit, i, for example, I get&lt;br&gt;
&amp;gt; ? disp(i &amp;lt; 0 | i == 0)&lt;br&gt;
&amp;gt; ans =&lt;br&gt;
&amp;gt; &#160; &#160; &#160;0&lt;br&gt;
&amp;gt; This may be consistent behavior. But it is certainly inconsistent with the following result:&lt;br&gt;
&amp;gt; ? disp (i &amp;lt;= 0)&lt;br&gt;
&amp;gt; ans =&lt;br&gt;
&amp;gt; &#160; &#160; &#160;1&lt;br&gt;
&lt;br&gt;
That's interesting:&lt;br&gt;
&amp;gt;&amp;gt; disp(i&amp;gt;0)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&lt;br&gt;
&amp;gt;&amp;gt; disp(i&amp;gt;=0)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&lt;br&gt;
&amp;gt;&amp;gt; disp(i==0)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&lt;br&gt;
&amp;gt;&amp;gt; disp(i&amp;lt;=0)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&lt;br&gt;
&amp;gt;&amp;gt; disp(i&amp;lt;0)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&lt;br&gt;
&lt;br&gt;
But then again, why would you compare i to zero anyways?&lt;br&gt;
&lt;br&gt;
-Nathan</description>
    </item>
    <item>
      <pubDate>Fri, 30 Oct 2009 21:15:20 -0400</pubDate>
      <title>Re: i &lt;= 0 ??</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264608#691090</link>
      <author>Bruno Luong</author>
      <description>From the doc:&lt;br&gt;
&lt;br&gt;
[... The operators &amp;lt;, &amp;gt;, &amp;lt;=, and &amp;gt;= use only the real part of their operands for the comparison. The operators == and ~= test real and imaginary parts. ..]&lt;br&gt;
&lt;br&gt;
And to confuse even more, SORT uses another relation ordering (I believe the *magnitude* is compared)&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; sort([1+1i 2i])&lt;br&gt;
&lt;br&gt;
ans =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;1.0000 + 1.0000i        0 + 2.0000i&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; 1+1i&amp;lt;=2i&lt;br&gt;
&lt;br&gt;
ans =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&lt;br&gt;
&lt;br&gt;
% Bruno</description>
    </item>
    <item>
      <pubDate>Fri, 30 Oct 2009 21:22:01 -0400</pubDate>
      <title>Re: i &lt;= 0 ??</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264608#691091</link>
      <author>Bruno Luong</author>
      <description>And you have not finish with another astonishing rule:&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; sort([0 1 -2])&lt;br&gt;
&lt;br&gt;
ans =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-2     0     1 &lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;gt;&amp;gt; sort([1i 1 -2])&lt;br&gt;
&lt;br&gt;
ans =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;1.0000                  0 + 1.0000i  -2.0000          % 1 &amp;lt;= -2 !!!&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
% Bruno</description>
    </item>
    <item>
      <pubDate>Fri, 30 Oct 2009 21:38:30 -0400</pubDate>
      <title>Re: i &lt;= 0 ??</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264608#691098</link>
      <author>Nasser M. Abbasi</author>
      <description>&lt;br&gt;
&quot;Muhammad &quot; &amp;lt;muhali@shaw.ca&amp;gt; wrote in message &lt;br&gt;
news:hcfjrm$jcs$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; Complex number are ordered in matlab. For the imaginary unit, i, for &lt;br&gt;
&amp;gt; example, I get&lt;br&gt;
&amp;gt; ? disp(i &amp;lt; 0 | i == 0)&lt;br&gt;
&amp;gt; ans =&lt;br&gt;
&amp;gt;     0&lt;br&gt;
&amp;gt; This may be consistent behavior. But it is certainly inconsistent with the &lt;br&gt;
&amp;gt; following result:&lt;br&gt;
&amp;gt; ? disp (i &amp;lt;= 0)&lt;br&gt;
&amp;gt; ans =&lt;br&gt;
&amp;gt;     1&lt;br&gt;
&lt;br&gt;
Ordering where complex numbers are involved should be based on the real &lt;br&gt;
parts. If 2 complex numbers have the same real part, then the imaginary part &lt;br&gt;
(its absolute value) should break the tie.&lt;br&gt;
&lt;br&gt;
In the first example,   i&amp;lt;0 , here since real part of i which is 0 is NOT &lt;br&gt;
less than zero then i&amp;lt;0 is false.  For i==0, since the real parts are equal &lt;br&gt;
(both are zero) then we look at the imaginary part to break the tie. Since &lt;br&gt;
the abs value of the imaginary part of i (which is 1) is clearly not equal &lt;br&gt;
to the imaginary part of zero, which is zero, then we get False again. &lt;br&gt;
Hence the result false Or False is False as shown.&lt;br&gt;
&lt;br&gt;
For the case of i&amp;lt;=0, the real part of i is zero, and the real part of 0 is &lt;br&gt;
zero, so it is a tie, looking at the imaginary parts, the absolute value of &lt;br&gt;
the imaginary part of i is 1, and the for 0 it is zero, hence 1&amp;lt;=0 should be &lt;br&gt;
False.&lt;br&gt;
&lt;br&gt;
Hence Matlab answer for i&amp;lt;=0  should be 0 not 1. This is a bug. Or Matlab &lt;br&gt;
uses some other logic to decide on these issues.&lt;br&gt;
&lt;br&gt;
--Nasser </description>
    </item>
    <item>
      <pubDate>Fri, 30 Oct 2009 22:20:19 -0400</pubDate>
      <title>Re: i &lt;= 0 ??</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264608#691107</link>
      <author>James Tursa</author>
      <description>&quot;Nasser M. Abbasi&quot; &amp;lt;nma@12000.org&amp;gt; wrote in message &amp;lt;s1JGm.37806$Tx1.13127@newsfe15.iad&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hence Matlab answer for i&amp;lt;=0  should be 0 not 1. This is a bug.&lt;br&gt;
&lt;br&gt;
No.&lt;br&gt;
&lt;br&gt;
&amp;gt; Or Matlab uses some other logic to decide on these issues.&lt;br&gt;
&lt;br&gt;
Yes, they use the rules they list in the doc for these operators. See Bruno's earlier post for the rules in the doc:&lt;br&gt;
&lt;br&gt;
[... The operators &amp;lt;, &amp;gt;, &amp;lt;=, and &amp;gt;= use only the real part of their operands for the comparison. The operators == and ~= test real and imaginary parts. ..]&lt;br&gt;
&lt;br&gt;
I don't see any discrepancy between this example and their documented rules. Now if you don't like their documented rules, that is another matter ...&lt;br&gt;
&lt;br&gt;
James Tursa</description>
    </item>
    <item>
      <pubDate>Sun, 08 Nov 2009 16:17:01 -0500</pubDate>
      <title>Re: i &lt;= 0 ??</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264608#693027</link>
      <author>Matt </author>
      <description>&quot;Bruno Luong&quot; &amp;lt;b.luong@fogale.findmycountry&amp;gt; wrote in message &amp;lt;hcfldp$pr1$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; And you have not finish with another astonishing rule:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; sort([0 1 -2])&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ans =&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;     -2     0     1 &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;  &amp;gt;&amp;gt; sort([1i 1 -2])&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ans =&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;    1.0000                  0 + 1.0000i  -2.0000          % 1 &amp;lt;= -2 !!!&lt;br&gt;
&lt;br&gt;
Hazardous indeed. A likely pitfall is, for example, if you want to sort the result of an ifft() output. Often you expect the output to be real-valued, and would expect the sorting to be done according to the real-part only, but forget that the output will have a residual complex part due to numerical round-off.&lt;br&gt;
&lt;br&gt;
I guess it's worth cooking up a realsort() function and getting into the habit of using that...</description>
    </item>
  </channel>
</rss>

