Different results for row reduction in Matlab












1












$begingroup$


Consider the following matrix:
$ left[ begin{array}{ccc}
-0.05 & 0.45 & 0 \
0.05 & -0.45 & 0 end{array} right] $



Row reducing the above matrix in Matlab using the rref() function produces what I would expect (just adding top row to bottom row and scaling top row):
$ left[ begin{array}{ccc}
1.0 & -9.0 & 0 \
0 & 0 & 0 end{array} right] $



But if I remove the last column of just zeros, and row reduce that matrix, I get a 2x2 identity matrix:
$ left[ begin{array}{ccc}
-0.05 & 0.45 \
0.05 & -0.45 end{array} right] sim
left[ begin{array}{ccc}
1 & 0 \
0 & 1 end{array} right] $



I can't see how removing the last column changes anything; adding the top row to the bottom row will still produce the result above, just without the last column of $0$'s. But I'm quite sure Matlab is right and I'm not, so what am I missing here?



Edit: I have managed to reproduce the above and I believe it's all due to rounding errors. If you input $ M = left[ begin{array}{ccc}
0.95 & 0.45 \
0.05 & .55 end{array} right] $
and then do $ A = M - eye(2) $. rref(A) will now give the $2 times 2$ identity matrix. If I enter the result of $M-eye(2)$ directly, that is $B= left[ begin{array}{ccc}
-0.05 & 0.45 \ 0.05 & -0.45 end{array} right] $
, then rref(B) returns the expected $ left[ begin{array}{ccc}
1 & -9 \
0 & 0 end{array} right] $
.



Here's a screenshot as an example:



enter image description here










share|cite|improve this question











$endgroup$












  • $begingroup$
    Are you sure you're getting an identity matrix for the $2times 2$ case? The matrix you have there is singular, after all.
    $endgroup$
    – J. M. is not a mathematician
    Oct 20 '11 at 13:35






  • 1




    $begingroup$
    I've just introduced your matrix on my Matlab and said to row reduce it with rref(A) and the result is the correct one: your second matrix, without the third column of zeros.
    $endgroup$
    – d.t.
    Oct 20 '11 at 13:48










  • $begingroup$
    @J.M. and Agusti, I think I might have narrowed it down to a rounding error, causing the top and bottom row to be slightly different (but not shown due to lack of decimals shown in Matlab). As you are both more experienced here than me, do you think I should answer my own post or delete it? Thank you!
    $endgroup$
    – Jodles
    Oct 20 '11 at 15:40










  • $begingroup$
    What version of MATLAB are you using? No, don't delete; this might be a nice cautionary tale... (You might want to post a screenshot of what you gave MATLAB as input.)
    $endgroup$
    – J. M. is not a mathematician
    Oct 20 '11 at 15:48








  • 1




    $begingroup$
    It's a cautionary example for using rank functions. For the example above rank(A) returns 1, but rref(A) thinks it's 2. You can tweak it though >> rref(A) ans = 1 0 0 1 >> rref(A,1E-15) ans = 1.0000 -9.0000 0 0 >> I'm surprised that the default eps value ends up with wrong result as well.
    $endgroup$
    – karakfa
    Oct 20 '11 at 17:00


















1












$begingroup$


Consider the following matrix:
$ left[ begin{array}{ccc}
-0.05 & 0.45 & 0 \
0.05 & -0.45 & 0 end{array} right] $



Row reducing the above matrix in Matlab using the rref() function produces what I would expect (just adding top row to bottom row and scaling top row):
$ left[ begin{array}{ccc}
1.0 & -9.0 & 0 \
0 & 0 & 0 end{array} right] $



But if I remove the last column of just zeros, and row reduce that matrix, I get a 2x2 identity matrix:
$ left[ begin{array}{ccc}
-0.05 & 0.45 \
0.05 & -0.45 end{array} right] sim
left[ begin{array}{ccc}
1 & 0 \
0 & 1 end{array} right] $



I can't see how removing the last column changes anything; adding the top row to the bottom row will still produce the result above, just without the last column of $0$'s. But I'm quite sure Matlab is right and I'm not, so what am I missing here?



Edit: I have managed to reproduce the above and I believe it's all due to rounding errors. If you input $ M = left[ begin{array}{ccc}
0.95 & 0.45 \
0.05 & .55 end{array} right] $
and then do $ A = M - eye(2) $. rref(A) will now give the $2 times 2$ identity matrix. If I enter the result of $M-eye(2)$ directly, that is $B= left[ begin{array}{ccc}
-0.05 & 0.45 \ 0.05 & -0.45 end{array} right] $
, then rref(B) returns the expected $ left[ begin{array}{ccc}
1 & -9 \
0 & 0 end{array} right] $
.



Here's a screenshot as an example:



enter image description here










share|cite|improve this question











$endgroup$












  • $begingroup$
    Are you sure you're getting an identity matrix for the $2times 2$ case? The matrix you have there is singular, after all.
    $endgroup$
    – J. M. is not a mathematician
    Oct 20 '11 at 13:35






  • 1




    $begingroup$
    I've just introduced your matrix on my Matlab and said to row reduce it with rref(A) and the result is the correct one: your second matrix, without the third column of zeros.
    $endgroup$
    – d.t.
    Oct 20 '11 at 13:48










  • $begingroup$
    @J.M. and Agusti, I think I might have narrowed it down to a rounding error, causing the top and bottom row to be slightly different (but not shown due to lack of decimals shown in Matlab). As you are both more experienced here than me, do you think I should answer my own post or delete it? Thank you!
    $endgroup$
    – Jodles
    Oct 20 '11 at 15:40










  • $begingroup$
    What version of MATLAB are you using? No, don't delete; this might be a nice cautionary tale... (You might want to post a screenshot of what you gave MATLAB as input.)
    $endgroup$
    – J. M. is not a mathematician
    Oct 20 '11 at 15:48








  • 1




    $begingroup$
    It's a cautionary example for using rank functions. For the example above rank(A) returns 1, but rref(A) thinks it's 2. You can tweak it though >> rref(A) ans = 1 0 0 1 >> rref(A,1E-15) ans = 1.0000 -9.0000 0 0 >> I'm surprised that the default eps value ends up with wrong result as well.
    $endgroup$
    – karakfa
    Oct 20 '11 at 17:00
















1












1








1





$begingroup$


Consider the following matrix:
$ left[ begin{array}{ccc}
-0.05 & 0.45 & 0 \
0.05 & -0.45 & 0 end{array} right] $



Row reducing the above matrix in Matlab using the rref() function produces what I would expect (just adding top row to bottom row and scaling top row):
$ left[ begin{array}{ccc}
1.0 & -9.0 & 0 \
0 & 0 & 0 end{array} right] $



But if I remove the last column of just zeros, and row reduce that matrix, I get a 2x2 identity matrix:
$ left[ begin{array}{ccc}
-0.05 & 0.45 \
0.05 & -0.45 end{array} right] sim
left[ begin{array}{ccc}
1 & 0 \
0 & 1 end{array} right] $



I can't see how removing the last column changes anything; adding the top row to the bottom row will still produce the result above, just without the last column of $0$'s. But I'm quite sure Matlab is right and I'm not, so what am I missing here?



Edit: I have managed to reproduce the above and I believe it's all due to rounding errors. If you input $ M = left[ begin{array}{ccc}
0.95 & 0.45 \
0.05 & .55 end{array} right] $
and then do $ A = M - eye(2) $. rref(A) will now give the $2 times 2$ identity matrix. If I enter the result of $M-eye(2)$ directly, that is $B= left[ begin{array}{ccc}
-0.05 & 0.45 \ 0.05 & -0.45 end{array} right] $
, then rref(B) returns the expected $ left[ begin{array}{ccc}
1 & -9 \
0 & 0 end{array} right] $
.



Here's a screenshot as an example:



enter image description here










share|cite|improve this question











$endgroup$




Consider the following matrix:
$ left[ begin{array}{ccc}
-0.05 & 0.45 & 0 \
0.05 & -0.45 & 0 end{array} right] $



Row reducing the above matrix in Matlab using the rref() function produces what I would expect (just adding top row to bottom row and scaling top row):
$ left[ begin{array}{ccc}
1.0 & -9.0 & 0 \
0 & 0 & 0 end{array} right] $



But if I remove the last column of just zeros, and row reduce that matrix, I get a 2x2 identity matrix:
$ left[ begin{array}{ccc}
-0.05 & 0.45 \
0.05 & -0.45 end{array} right] sim
left[ begin{array}{ccc}
1 & 0 \
0 & 1 end{array} right] $



I can't see how removing the last column changes anything; adding the top row to the bottom row will still produce the result above, just without the last column of $0$'s. But I'm quite sure Matlab is right and I'm not, so what am I missing here?



Edit: I have managed to reproduce the above and I believe it's all due to rounding errors. If you input $ M = left[ begin{array}{ccc}
0.95 & 0.45 \
0.05 & .55 end{array} right] $
and then do $ A = M - eye(2) $. rref(A) will now give the $2 times 2$ identity matrix. If I enter the result of $M-eye(2)$ directly, that is $B= left[ begin{array}{ccc}
-0.05 & 0.45 \ 0.05 & -0.45 end{array} right] $
, then rref(B) returns the expected $ left[ begin{array}{ccc}
1 & -9 \
0 & 0 end{array} right] $
.



Here's a screenshot as an example:



enter image description here







linear-algebra matlab






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Jan 1 at 10:47









Glorfindel

3,41981830




3,41981830










asked Oct 20 '11 at 13:03









JodlesJodles

345419




345419












  • $begingroup$
    Are you sure you're getting an identity matrix for the $2times 2$ case? The matrix you have there is singular, after all.
    $endgroup$
    – J. M. is not a mathematician
    Oct 20 '11 at 13:35






  • 1




    $begingroup$
    I've just introduced your matrix on my Matlab and said to row reduce it with rref(A) and the result is the correct one: your second matrix, without the third column of zeros.
    $endgroup$
    – d.t.
    Oct 20 '11 at 13:48










  • $begingroup$
    @J.M. and Agusti, I think I might have narrowed it down to a rounding error, causing the top and bottom row to be slightly different (but not shown due to lack of decimals shown in Matlab). As you are both more experienced here than me, do you think I should answer my own post or delete it? Thank you!
    $endgroup$
    – Jodles
    Oct 20 '11 at 15:40










  • $begingroup$
    What version of MATLAB are you using? No, don't delete; this might be a nice cautionary tale... (You might want to post a screenshot of what you gave MATLAB as input.)
    $endgroup$
    – J. M. is not a mathematician
    Oct 20 '11 at 15:48








  • 1




    $begingroup$
    It's a cautionary example for using rank functions. For the example above rank(A) returns 1, but rref(A) thinks it's 2. You can tweak it though >> rref(A) ans = 1 0 0 1 >> rref(A,1E-15) ans = 1.0000 -9.0000 0 0 >> I'm surprised that the default eps value ends up with wrong result as well.
    $endgroup$
    – karakfa
    Oct 20 '11 at 17:00




















  • $begingroup$
    Are you sure you're getting an identity matrix for the $2times 2$ case? The matrix you have there is singular, after all.
    $endgroup$
    – J. M. is not a mathematician
    Oct 20 '11 at 13:35






  • 1




    $begingroup$
    I've just introduced your matrix on my Matlab and said to row reduce it with rref(A) and the result is the correct one: your second matrix, without the third column of zeros.
    $endgroup$
    – d.t.
    Oct 20 '11 at 13:48










  • $begingroup$
    @J.M. and Agusti, I think I might have narrowed it down to a rounding error, causing the top and bottom row to be slightly different (but not shown due to lack of decimals shown in Matlab). As you are both more experienced here than me, do you think I should answer my own post or delete it? Thank you!
    $endgroup$
    – Jodles
    Oct 20 '11 at 15:40










  • $begingroup$
    What version of MATLAB are you using? No, don't delete; this might be a nice cautionary tale... (You might want to post a screenshot of what you gave MATLAB as input.)
    $endgroup$
    – J. M. is not a mathematician
    Oct 20 '11 at 15:48








  • 1




    $begingroup$
    It's a cautionary example for using rank functions. For the example above rank(A) returns 1, but rref(A) thinks it's 2. You can tweak it though >> rref(A) ans = 1 0 0 1 >> rref(A,1E-15) ans = 1.0000 -9.0000 0 0 >> I'm surprised that the default eps value ends up with wrong result as well.
    $endgroup$
    – karakfa
    Oct 20 '11 at 17:00


















$begingroup$
Are you sure you're getting an identity matrix for the $2times 2$ case? The matrix you have there is singular, after all.
$endgroup$
– J. M. is not a mathematician
Oct 20 '11 at 13:35




$begingroup$
Are you sure you're getting an identity matrix for the $2times 2$ case? The matrix you have there is singular, after all.
$endgroup$
– J. M. is not a mathematician
Oct 20 '11 at 13:35




1




1




$begingroup$
I've just introduced your matrix on my Matlab and said to row reduce it with rref(A) and the result is the correct one: your second matrix, without the third column of zeros.
$endgroup$
– d.t.
Oct 20 '11 at 13:48




$begingroup$
I've just introduced your matrix on my Matlab and said to row reduce it with rref(A) and the result is the correct one: your second matrix, without the third column of zeros.
$endgroup$
– d.t.
Oct 20 '11 at 13:48












$begingroup$
@J.M. and Agusti, I think I might have narrowed it down to a rounding error, causing the top and bottom row to be slightly different (but not shown due to lack of decimals shown in Matlab). As you are both more experienced here than me, do you think I should answer my own post or delete it? Thank you!
$endgroup$
– Jodles
Oct 20 '11 at 15:40




$begingroup$
@J.M. and Agusti, I think I might have narrowed it down to a rounding error, causing the top and bottom row to be slightly different (but not shown due to lack of decimals shown in Matlab). As you are both more experienced here than me, do you think I should answer my own post or delete it? Thank you!
$endgroup$
– Jodles
Oct 20 '11 at 15:40












$begingroup$
What version of MATLAB are you using? No, don't delete; this might be a nice cautionary tale... (You might want to post a screenshot of what you gave MATLAB as input.)
$endgroup$
– J. M. is not a mathematician
Oct 20 '11 at 15:48






$begingroup$
What version of MATLAB are you using? No, don't delete; this might be a nice cautionary tale... (You might want to post a screenshot of what you gave MATLAB as input.)
$endgroup$
– J. M. is not a mathematician
Oct 20 '11 at 15:48






1




1




$begingroup$
It's a cautionary example for using rank functions. For the example above rank(A) returns 1, but rref(A) thinks it's 2. You can tweak it though >> rref(A) ans = 1 0 0 1 >> rref(A,1E-15) ans = 1.0000 -9.0000 0 0 >> I'm surprised that the default eps value ends up with wrong result as well.
$endgroup$
– karakfa
Oct 20 '11 at 17:00






$begingroup$
It's a cautionary example for using rank functions. For the example above rank(A) returns 1, but rref(A) thinks it's 2. You can tweak it though >> rref(A) ans = 1 0 0 1 >> rref(A,1E-15) ans = 1.0000 -9.0000 0 0 >> I'm surprised that the default eps value ends up with wrong result as well.
$endgroup$
– karakfa
Oct 20 '11 at 17:00












1 Answer
1






active

oldest

votes


















3












$begingroup$

This is already documented in MATLAB.




Roundoff errors may cause this algorithm to compute a different value for the rank than rank, orth and null.




You need to type format long e. After that you can see the difference if you execute N-eye(2) resulting with



N-eye(2)

ans =

-5.000000000000004e-002 4.500000000000000e-001
5.000000000000000e-002 -4.500000000000000e-001


Here, the trouble is already visible in the (1,1) element of the matrix. But also



 [1 1]*(N-eye(2))

ans =

-4.163336342344337e-017 5.551115123125783e-017


gives you the error between seemingly identical elements.



The reason why you get correct results with an additional zero column is (my personal view) due to the term in the tolerance computation for rref given by (max(size(A))*eps *norm(A,inf)). Here, the first term is 3 instead of 2 and that should make the small difference between selecting a rank 1 and rank 2 matrix.






share|cite|improve this answer









$endgroup$













    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "69"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    noCode: true, onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f74298%2fdifferent-results-for-row-reduction-in-matlab%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3












    $begingroup$

    This is already documented in MATLAB.




    Roundoff errors may cause this algorithm to compute a different value for the rank than rank, orth and null.




    You need to type format long e. After that you can see the difference if you execute N-eye(2) resulting with



    N-eye(2)

    ans =

    -5.000000000000004e-002 4.500000000000000e-001
    5.000000000000000e-002 -4.500000000000000e-001


    Here, the trouble is already visible in the (1,1) element of the matrix. But also



     [1 1]*(N-eye(2))

    ans =

    -4.163336342344337e-017 5.551115123125783e-017


    gives you the error between seemingly identical elements.



    The reason why you get correct results with an additional zero column is (my personal view) due to the term in the tolerance computation for rref given by (max(size(A))*eps *norm(A,inf)). Here, the first term is 3 instead of 2 and that should make the small difference between selecting a rank 1 and rank 2 matrix.






    share|cite|improve this answer









    $endgroup$


















      3












      $begingroup$

      This is already documented in MATLAB.




      Roundoff errors may cause this algorithm to compute a different value for the rank than rank, orth and null.




      You need to type format long e. After that you can see the difference if you execute N-eye(2) resulting with



      N-eye(2)

      ans =

      -5.000000000000004e-002 4.500000000000000e-001
      5.000000000000000e-002 -4.500000000000000e-001


      Here, the trouble is already visible in the (1,1) element of the matrix. But also



       [1 1]*(N-eye(2))

      ans =

      -4.163336342344337e-017 5.551115123125783e-017


      gives you the error between seemingly identical elements.



      The reason why you get correct results with an additional zero column is (my personal view) due to the term in the tolerance computation for rref given by (max(size(A))*eps *norm(A,inf)). Here, the first term is 3 instead of 2 and that should make the small difference between selecting a rank 1 and rank 2 matrix.






      share|cite|improve this answer









      $endgroup$
















        3












        3








        3





        $begingroup$

        This is already documented in MATLAB.




        Roundoff errors may cause this algorithm to compute a different value for the rank than rank, orth and null.




        You need to type format long e. After that you can see the difference if you execute N-eye(2) resulting with



        N-eye(2)

        ans =

        -5.000000000000004e-002 4.500000000000000e-001
        5.000000000000000e-002 -4.500000000000000e-001


        Here, the trouble is already visible in the (1,1) element of the matrix. But also



         [1 1]*(N-eye(2))

        ans =

        -4.163336342344337e-017 5.551115123125783e-017


        gives you the error between seemingly identical elements.



        The reason why you get correct results with an additional zero column is (my personal view) due to the term in the tolerance computation for rref given by (max(size(A))*eps *norm(A,inf)). Here, the first term is 3 instead of 2 and that should make the small difference between selecting a rank 1 and rank 2 matrix.






        share|cite|improve this answer









        $endgroup$



        This is already documented in MATLAB.




        Roundoff errors may cause this algorithm to compute a different value for the rank than rank, orth and null.




        You need to type format long e. After that you can see the difference if you execute N-eye(2) resulting with



        N-eye(2)

        ans =

        -5.000000000000004e-002 4.500000000000000e-001
        5.000000000000000e-002 -4.500000000000000e-001


        Here, the trouble is already visible in the (1,1) element of the matrix. But also



         [1 1]*(N-eye(2))

        ans =

        -4.163336342344337e-017 5.551115123125783e-017


        gives you the error between seemingly identical elements.



        The reason why you get correct results with an additional zero column is (my personal view) due to the term in the tolerance computation for rref given by (max(size(A))*eps *norm(A,inf)). Here, the first term is 3 instead of 2 and that should make the small difference between selecting a rank 1 and rank 2 matrix.







        share|cite|improve this answer












        share|cite|improve this answer



        share|cite|improve this answer










        answered Oct 20 '11 at 21:55







        user13838





































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Mathematics Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f74298%2fdifferent-results-for-row-reduction-in-matlab%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

            Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

            A Topological Invariant for $pi_3(U(n))$