<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Matlab numerical gotchas	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/matlab-numerical-gotchas/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/matlab-numerical-gotchas?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=matlab-numerical-gotchas</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Thu, 09 Jan 2014 13:35:06 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>
		By: Sami Varjo		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-numerical-gotchas#comment-308265</link>

		<dc:creator><![CDATA[Sami Varjo]]></dc:creator>
		<pubDate>Thu, 09 Jan 2014 13:35:06 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4313#comment-308265</guid>

					<description><![CDATA[It was &quot;cool&quot; to note that the weak typing favors integers in arrays. One would expect that the more weak variable would be promoted as the floating point presentation is usually default, however:

&lt;pre lang=&quot;matlab&quot;&gt; 
&gt;&gt; myUint8Var = uint8(0);
&gt;&gt; newVector = [myUint8Var 510.14 45.24 1.2]
newVector =
    0  255   45    1
&lt;/pre&gt;

This actually happens also if you preallocate an array for a number of vectors where you assign the values:

&lt;pre lang=&quot;matlab&quot;&gt;
&gt;&gt; array = zeros(3,4,&#039;double&#039;);
&gt;&gt; array(1,:) = [myUint8Var 510.14 45.24 1.2]
array =
0   255    45     1
0     0     0     0
0     0     0     0
&lt;/pre&gt;

So also here explicit type cast for myUint8Var is required for &lt;strike&gt;expected&lt;/strike&gt; assumed behavior (R2012a). This one haunted me quite a while...]]></description>
			<content:encoded><![CDATA[<p>It was &#8220;cool&#8221; to note that the weak typing favors integers in arrays. One would expect that the more weak variable would be promoted as the floating point presentation is usually default, however:</p>
<pre lang="matlab"> 
>> myUint8Var = uint8(0);
>> newVector = [myUint8Var 510.14 45.24 1.2]
newVector =
    0  255   45    1
</pre>
<p>This actually happens also if you preallocate an array for a number of vectors where you assign the values:</p>
<pre lang="matlab">
>> array = zeros(3,4,'double');
>> array(1,:) = [myUint8Var 510.14 45.24 1.2]
array =
0   255    45     1
0     0     0     0
0     0     0     0
</pre>
<p>So also here explicit type cast for myUint8Var is required for <strike>expected</strike> assumed behavior (R2012a). This one haunted me quite a while&#8230;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Malcolm Lidierth		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-numerical-gotchas#comment-296593</link>

		<dc:creator><![CDATA[Malcolm Lidierth]]></dc:creator>
		<pubDate>Mon, 18 Nov 2013 16:04:31 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4313#comment-296593</guid>

					<description><![CDATA[Take a Java method with signatures accepting either:

a scalar int
a double[]

as input.

MATLAB&#039;s Java reflection mechanism will pass a scalar &lt;a href=&quot;http://www.mathworks.com/company/newsletters/news_notes/pdf/Fall96Cleve.pdf&quot; rel=&quot;nofollow&quot;&gt;flint&lt;/a&gt; as a double[] to the second method by default. To invoke the method with an int input, it needs to be cast explicitly to an int.]]></description>
			<content:encoded><![CDATA[<p>Take a Java method with signatures accepting either:</p>
<p>a scalar int<br />
a double[]</p>
<p>as input.</p>
<p>MATLAB&#8217;s Java reflection mechanism will pass a scalar <a href="http://www.mathworks.com/company/newsletters/news_notes/pdf/Fall96Cleve.pdf" rel="nofollow">flint</a> as a double[] to the second method by default. To invoke the method with an int input, it needs to be cast explicitly to an int.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Daniel E. Shub		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-numerical-gotchas#comment-294386</link>

		<dc:creator><![CDATA[Daniel E. Shub]]></dc:creator>
		<pubDate>Mon, 11 Nov 2013 12:06:31 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4313#comment-294386</guid>

					<description><![CDATA[Despite the documentation for the colon function I cannot help but expect x = 0:0.1:1; to be equal to [0*0.1, 1*0.1, 2*0.1, ..., 10*0.1] as that is how I describe the function working. This can cause a gotcha when checking for subsets

&#062;&#062; x = 0:0.1:1;
&#062;&#062; y = 0:0.1:0.5;
&#062;&#062; isequal(x(1:6), y(1:6))]]></description>
			<content:encoded><![CDATA[<p>Despite the documentation for the colon function I cannot help but expect x = 0:0.1:1; to be equal to [0*0.1, 1*0.1, 2*0.1, &#8230;, 10*0.1] as that is how I describe the function working. This can cause a gotcha when checking for subsets</p>
<p>&gt;&gt; x = 0:0.1:1;<br />
&gt;&gt; y = 0:0.1:0.5;<br />
&gt;&gt; isequal(x(1:6), y(1:6))</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-numerical-gotchas#comment-292724</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 06 Nov 2013 19:39:06 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4313#comment-292724</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/matlab-numerical-gotchas#comment-292554&quot;&gt;Guillaume&lt;/a&gt;.

@Guillaume - thanks for the correction. It serves me right for copying wiki math without double checking. I have now corrected both the main article and the referenced FAQ one.

BTW - it appears that like me, you have also gotten an error in your comment: I believe that the correct roots are 2e^iπ, 2e^iπ/3 and 2e^-iπ/3, and not as you have stated.
:-)]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/matlab-numerical-gotchas#comment-292554">Guillaume</a>.</p>
<p>@Guillaume &#8211; thanks for the correction. It serves me right for copying wiki math without double checking. I have now corrected both the main article and the referenced FAQ one.</p>
<p>BTW &#8211; it appears that like me, you have also gotten an error in your comment: I believe that the correct roots are 2e^iπ, 2e^iπ/3 and 2e^-iπ/3, and not as you have stated.<br />
🙂</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Guillaume		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-numerical-gotchas#comment-292554</link>

		<dc:creator><![CDATA[Guillaume]]></dc:creator>
		<pubDate>Wed, 06 Nov 2013 09:24:10 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4313#comment-292554</guid>

					<description><![CDATA[Hmm, 2e^2iπ/3 is not a cube root of -8. The correct formula for nth roots of Ae^iθ is A^1/n * e^i(θ/n + 2kπ/n). Hence, cube roots of -8 are 2e^iπ (k=1), 2e^-iπ (k=2) and 2e^iπ/3 (k=3).]]></description>
			<content:encoded><![CDATA[<p>Hmm, 2e^2iπ/3 is not a cube root of -8. The correct formula for nth roots of Ae^iθ is A^1/n * e^i(θ/n + 2kπ/n). Hence, cube roots of -8 are 2e^iπ (k=1), 2e^-iπ (k=2) and 2e^iπ/3 (k=3).</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: the cyclist		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-numerical-gotchas#comment-291336</link>

		<dc:creator><![CDATA[the cyclist]]></dc:creator>
		<pubDate>Fri, 01 Nov 2013 20:56:31 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4313#comment-291336</guid>

					<description><![CDATA[I find it surprising that min(0,NaN) returns a result of 0 rather than NaN.

There is some discussion of this here: 

http://www.mathworks.com/matlabcentral/answers/38999-what-is-the-reasoning-behind-the-fact-that-min-0-nan-is-0]]></description>
			<content:encoded><![CDATA[<p>I find it surprising that min(0,NaN) returns a result of 0 rather than NaN.</p>
<p>There is some discussion of this here: </p>
<p><a href="http://www.mathworks.com/matlabcentral/answers/38999-what-is-the-reasoning-behind-the-fact-that-min-0-nan-is-0" rel="nofollow ugc">http://www.mathworks.com/matlabcentral/answers/38999-what-is-the-reasoning-behind-the-fact-that-min-0-nan-is-0</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Wesley Brodsky		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-numerical-gotchas#comment-291276</link>

		<dc:creator><![CDATA[Wesley Brodsky]]></dc:creator>
		<pubDate>Fri, 01 Nov 2013 17:28:15 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4313#comment-291276</guid>

					<description><![CDATA[One problem I have noticed in the past, which might still exist, is one of the &quot;creeping imaginary part&quot;. After a long series of calculations with all real numbers, a teeny-weenie imaginary part (&#060;10^-10 times real part) appears. This causes an error if input to a function that only accepts real numbers. This is not the same as the cube-root issue, since the real part is what I expect. I place x = real(x) at random places in the calculations to avoid this. The problem might no longer exist, but I have not experimented to find out.

Has anyone else seen this?]]></description>
			<content:encoded><![CDATA[<p>One problem I have noticed in the past, which might still exist, is one of the &#8220;creeping imaginary part&#8221;. After a long series of calculations with all real numbers, a teeny-weenie imaginary part (&lt;10^-10 times real part) appears. This causes an error if input to a function that only accepts real numbers. This is not the same as the cube-root issue, since the real part is what I expect. I place x = real(x) at random places in the calculations to avoid this. The problem might no longer exist, but I have not experimented to find out.</p>
<p>Has anyone else seen this?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Chandrakanth		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-numerical-gotchas#comment-290934</link>

		<dc:creator><![CDATA[Chandrakanth]]></dc:creator>
		<pubDate>Thu, 31 Oct 2013 15:58:09 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4313#comment-290934</guid>

					<description><![CDATA[I think I have come across quite such &#039;gotachas&#039;, but this is the only one i can recollect now.
&lt;pre lang=&quot;matlab&quot;&gt; 
m&gt;=3  % is fine.
m&gt;= 3 % notice the space before 3. This is fine as well.
m &gt;= 3 % notice space before 3 and after m. This too is fine.
m &gt;=3 % space only after m. This complains with an error.
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>I think I have come across quite such &#8216;gotachas&#8217;, but this is the only one i can recollect now.</p>
<pre lang="matlab"> 
m>=3  % is fine.
m>= 3 % notice the space before 3. This is fine as well.
m >= 3 % notice space before 3 and after m. This too is fine.
m >=3 % space only after m. This complains with an error.
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Walter Roberson on Facebook		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-numerical-gotchas#comment-290698</link>

		<dc:creator><![CDATA[Walter Roberson on Facebook]]></dc:creator>
		<pubDate>Wed, 30 Oct 2013 21:08:28 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4313#comment-290698</guid>

					<description><![CDATA[Let A and B be positive. Then mod(-A,B) will return B itself, if A &lt; eps(B), instead of returning something in [0,B) as would normally be expected for mathematical modulus operator.]]></description>
			<content:encoded><![CDATA[<p>Let A and B be positive. Then mod(-A,B) will return B itself, if A < eps(B), instead of returning something in [0,B) as would normally be expected for mathematical modulus operator.
</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
