A serious bug in MATLAB 2009b?

November 30th, 2009 | Categories: math software, matlab | Tags:

One of the benefits of writing a blog is that people write to me and tell me all kinds of interesting things.  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=[ 2 ; 0 ];

ans =

which is, quite simply, wrong! The previous version of MATLAB, MATLAB 2009a, (along with MATLAB’s free clone – Octave) gets it right though:

ans =

so this is a new bug. Curiously, there is no problem with other matrices. For example the following, correct, result is given by 2009b:

A = [1 2 ; 1 1]

ans =

In case you don’t speak MATLAB, the command A’\b solves the matrix equation ATx = b for an unknown vector, x.  If you speak Mathematica then the equivalent command is

LinearSolve[Transpose[A], b]

Now, the MATLAB command transpose(A)\b is syntactically equivalent to A’\b and yet the former gives the correct result in this particular case:

ans =

What I find interesting about this particular bug is that it involves one of MATLAB’s core areas of functionality – 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?

Many thanks to Frank Schmidt who discovered this bug and gave me permission to copy his findings wholesale and also thanks to my colleague Chris Paul who made me aware of it.

Update 1 (1st December 2009): Thanks to ‘Zebb Prime’ who reminded me that ‘ is equivalent to the complex transpose – ctranspose() – and not transpose() as I put in the post above.  I got away with it in my post because we are dealing with real numbers.  This mistake doesn’t alter the fact that there is a bug.  The equivalent Mathematica code should be

LinearSolve[Conjugate[Transpose[A]], b]
  1. Zebb Prime
    November 30th, 2009 at 23:04
    Reply | Quote | #1

    I’m a little concerned, especially since mlint suggests using mldivide instead of inv(A)*b.

    Interestingly, the shorthand for non-conjugate transpose doesn’t have this bug either.

    >> A.’\b

    ans =


    Also, technically the function ctranspose() is syntactically equivalent to ‘

    Thanks for reporting this.

  2. Omid
    December 1st, 2009 at 05:23
    Reply | Quote | #2

    Hi Mike,

    That’s quite serious for sure. Transpose and backslash operators lie at the heart of MATLAB and if, for any reason, their functionality is broken, the whole system could collapse. I’m on R2009a so I can’t verify this, or look into it further, but I think it could have serious ramifications, as I don’t see a way to determine whether the case reported is the only “singular point.”

    I couldn’t find any bug reports about this on TMW’s website and I’m wondering if they are aware of the issue.


  3. December 1st, 2009 at 10:37
    Reply | Quote | #3

    @Zebb, thanks for the reminder re: ctranspose() and ‘ – It led to a head slapping moment last night :)

    @Omid – Frank Schmidt (who originally discovered this bug) has reported it to Mathworks. The example shown isn’t the only one which gives the wrong answer – I have found quite a few more and will post the code later today.

  4. December 1st, 2009 at 17:11
    Reply | Quote | #4

    Thanks to all the MATLAB Community members who have reported this bug and forwarded this information along.

    We have posted this Bug (583443) in our Bug Report system:


    Look under MATLAB, in the Mathematics Category, Exists In R2009b.

    MATLAB customers should feel free to Watch this Bug for any updates, or Subscribe to an RSS feed of a group of Bugs of interest.

    This Bug Report details the circumstances required to trigger the bug.

    The summary is that A must be the permutation of a full, square, non-scalar triangular matrix (but not exactly triangular) and must be used as A’\b in the solve.

    The Bug Report does not yet reflect this, but the bug will be fixed in our next release of MATLAB.

    Penny Anderson
    Manager, MATLAB Math
    The MathWorks

  5. December 1st, 2009 at 17:31
    Reply | Quote | #5

    Hi Penny

    Thanks for getting in touch and letting us know the extra details.

    Best Wishes,

  6. Michal Kvasnicka
    December 2nd, 2009 at 23:22
    Reply | Quote | #6

    OK, Penny confirm the well known fact, that R2009b contain bug. From my point of view, TMW must release fix patch as soon as possible, because there is a few more SERIOUS bugs (see http://www.mathworks.com/matlabcentral/newsreader/view_thread/267352#699123)

    The math core of the MATLAB must be reliable and trustworthy and the “stupid” workaround recommended by Steven Lord and by BugReport is rather amusing, but not conceptual.

    Of course, there is always a possibility to return to the previous version, but what then is the current version? Probably just an attempt to release new version on the time?


  7. December 3rd, 2009 at 10:53
    Reply | Quote | #7

    Hi Michal

    I have to admit that I would quite like a fix patch too! Some of these bugs are show stoppers.

    Best Wishes,