{"id":1964,"date":"2009-11-30T19:12:33","date_gmt":"2009-11-30T18:12:33","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=1964"},"modified":"2009-12-01T10:40:28","modified_gmt":"2009-12-01T09:40:28","slug":"a-serious-bug-in-matlab-2009b","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=1964","title":{"rendered":"A serious bug in MATLAB 2009b?"},"content":{"rendered":"<p>One of the benefits of writing a blog is that people write to me and tell me all kinds of interesting things.\u00a0 For example, early this morning a colleague of mine sent me the details of a bug in MATLAB 2009b which you can reproduce as follows.<\/p>\n<pre>A=[ 0 2 ; 1 0 ];\r\nb=[ 2 ; 0 ];\r\nA'\\b\r\n\r\nans =\r\n0\r\n1<\/pre>\n<p>which is, quite simply, wrong! The previous version of MATLAB, MATLAB 2009a, (along with MATLAB&#8217;s free clone &#8211; Octave) gets it right though:<\/p>\n<pre>ans =\r\n0\r\n2<\/pre>\n<p>so this is a new bug.  Curiously, there is no problem with other matrices.  For example the following, correct, result is given by 2009b:<\/p>\n<pre>A = [1 2 ; 1 1]\r\nA'\\b\r\n\r\nans =\r\n-2\r\n 4<\/pre>\n<p>In case you don&#8217;t speak MATLAB, the command A&#8217;\\b solves the matrix equation A<sup>T<\/sup>x = b for an unknown vector, x.\u00a0 If you speak Mathematica then the equivalent command is<\/p>\n<pre>LinearSolve[Transpose[A], b]<\/pre>\n<p>Now, the MATLAB command transpose(A)\\b is syntactically equivalent to A&#8217;\\b and yet the former gives the correct result in this particular case:<\/p>\n<pre>transpose(A)\\b\r\nans =\r\n   0\r\n   2<\/pre>\n<p>What I find interesting about this particular bug is that it involves one of MATLAB&#8217;s core areas of functionality &#8211; solving linear systems.  I wonder what readers of this blog think about it?  Is it a trivial bug that is unlikely to cause problems in the real world or is it something that we should be worried about?<\/p>\n<p>Many thanks to Frank Schmidt <a href=\"http:\/\/www.netlib.org\/na-digest-html\/09\/v09n48.html#1\">who discovered this bug<\/a> and gave me permission to copy his findings wholesale and also thanks to my colleague Chris Paul who made me aware of it.<\/p>\n<p><strong>Update 1 (1st December 2009): <\/strong>Thanks to &#8216;Zebb Prime&#8217; who reminded me that &#8216; is equivalent to the complex transpose &#8211; ctranspose() &#8211; and not transpose() as I put in the post above.\u00a0 I got away with it in my post because we are dealing with real numbers.\u00a0 This mistake doesn&#8217;t alter the fact that there is a bug.\u00a0 The equivalent Mathematica code should be<\/p>\n<pre>LinearSolve[Conjugate[Transpose[A]], b]<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>One of the benefits of writing a blog is that people write to me and tell me all kinds of interesting things.\u00a0 For example, early this morning a colleague of mine sent me the details of a bug in MATLAB 2009b which you can reproduce as follows. A=[ 0 2 ; 1 0 ]; b=[ [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,11],"tags":[],"class_list":["post-1964","post","type-post","status-publish","format-standard","hentry","category-math-software","category-matlab"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-vG","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/1964","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1964"}],"version-history":[{"count":9,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/1964\/revisions"}],"predecessor-version":[{"id":1973,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/1964\/revisions\/1973"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1964"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}