Symmetric Matrix Product is not Symmetric [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • Why is 24.0000 not equal to 24.0000 in MATLAB?

    6 answers




When we have two symmetric matrices x and y, the matrix z = xyx is theoretically also symmetric. However this is not exactly true in Matlab:



x = randn(3);
y = randn(3);
x = x*x';
y = x*x';
z = x*y*x;
issymetric(z)


Why does this happen and what can I do about it? Since I do not want to do



z = .5*(z+z')


all anwers in this stackoverflow question are unsatisfactionary.










share|improve this question













marked as duplicate by Sardar Usama, OmG, Luis Mendo matlab
Users with the  matlab badge can single-handedly close matlab questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
2 days ago


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















    up vote
    0
    down vote

    favorite













    This question already has an answer here:




    • Why is 24.0000 not equal to 24.0000 in MATLAB?

      6 answers




    When we have two symmetric matrices x and y, the matrix z = xyx is theoretically also symmetric. However this is not exactly true in Matlab:



    x = randn(3);
    y = randn(3);
    x = x*x';
    y = x*x';
    z = x*y*x;
    issymetric(z)


    Why does this happen and what can I do about it? Since I do not want to do



    z = .5*(z+z')


    all anwers in this stackoverflow question are unsatisfactionary.










    share|improve this question













    marked as duplicate by Sardar Usama, OmG, Luis Mendo matlab
    Users with the  matlab badge can single-handedly close matlab questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    2 days ago


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite












      This question already has an answer here:




      • Why is 24.0000 not equal to 24.0000 in MATLAB?

        6 answers




      When we have two symmetric matrices x and y, the matrix z = xyx is theoretically also symmetric. However this is not exactly true in Matlab:



      x = randn(3);
      y = randn(3);
      x = x*x';
      y = x*x';
      z = x*y*x;
      issymetric(z)


      Why does this happen and what can I do about it? Since I do not want to do



      z = .5*(z+z')


      all anwers in this stackoverflow question are unsatisfactionary.










      share|improve this question














      This question already has an answer here:




      • Why is 24.0000 not equal to 24.0000 in MATLAB?

        6 answers




      When we have two symmetric matrices x and y, the matrix z = xyx is theoretically also symmetric. However this is not exactly true in Matlab:



      x = randn(3);
      y = randn(3);
      x = x*x';
      y = x*x';
      z = x*y*x;
      issymetric(z)


      Why does this happen and what can I do about it? Since I do not want to do



      z = .5*(z+z')


      all anwers in this stackoverflow question are unsatisfactionary.





      This question already has an answer here:




      • Why is 24.0000 not equal to 24.0000 in MATLAB?

        6 answers








      matlab matrix symmetric






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      stollenm

      17217




      17217




      marked as duplicate by Sardar Usama, OmG, Luis Mendo matlab
      Users with the  matlab badge can single-handedly close matlab questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      2 days ago


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by Sardar Usama, OmG, Luis Mendo matlab
      Users with the  matlab badge can single-handedly close matlab questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      2 days ago


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          The problem is that Matlab does not perform the calculations exact, and thus the finite precision of the floating point calculations introduces some truncation errors.



          If you run the example with symbolic math (no truncation, exact), you will see that z is actually symmetric.



          x = sym(randn(3));
          y = sym(randn(3));
          x = x*x';
          y = y*y';
          z = x*y*x;

          % issymmetric does not take symbolic expressions as argument, convert to double
          issymmetric(double(z))


          Since you now do the double conversion at the end, and not in the intermediate steps, the matrix will remain symmetric.






          share|improve this answer




























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            The problem is that Matlab does not perform the calculations exact, and thus the finite precision of the floating point calculations introduces some truncation errors.



            If you run the example with symbolic math (no truncation, exact), you will see that z is actually symmetric.



            x = sym(randn(3));
            y = sym(randn(3));
            x = x*x';
            y = y*y';
            z = x*y*x;

            % issymmetric does not take symbolic expressions as argument, convert to double
            issymmetric(double(z))


            Since you now do the double conversion at the end, and not in the intermediate steps, the matrix will remain symmetric.






            share|improve this answer

























              up vote
              1
              down vote



              accepted










              The problem is that Matlab does not perform the calculations exact, and thus the finite precision of the floating point calculations introduces some truncation errors.



              If you run the example with symbolic math (no truncation, exact), you will see that z is actually symmetric.



              x = sym(randn(3));
              y = sym(randn(3));
              x = x*x';
              y = y*y';
              z = x*y*x;

              % issymmetric does not take symbolic expressions as argument, convert to double
              issymmetric(double(z))


              Since you now do the double conversion at the end, and not in the intermediate steps, the matrix will remain symmetric.






              share|improve this answer























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                The problem is that Matlab does not perform the calculations exact, and thus the finite precision of the floating point calculations introduces some truncation errors.



                If you run the example with symbolic math (no truncation, exact), you will see that z is actually symmetric.



                x = sym(randn(3));
                y = sym(randn(3));
                x = x*x';
                y = y*y';
                z = x*y*x;

                % issymmetric does not take symbolic expressions as argument, convert to double
                issymmetric(double(z))


                Since you now do the double conversion at the end, and not in the intermediate steps, the matrix will remain symmetric.






                share|improve this answer












                The problem is that Matlab does not perform the calculations exact, and thus the finite precision of the floating point calculations introduces some truncation errors.



                If you run the example with symbolic math (no truncation, exact), you will see that z is actually symmetric.



                x = sym(randn(3));
                y = sym(randn(3));
                x = x*x';
                y = y*y';
                z = x*y*x;

                % issymmetric does not take symbolic expressions as argument, convert to double
                issymmetric(double(z))


                Since you now do the double conversion at the end, and not in the intermediate steps, the matrix will remain symmetric.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 days ago









                rickert

                747316




                747316















                    Popular posts from this blog

                    Full-time equivalent

                    Bicuculline

                    さくらももこ