{"id":719,"date":"2013-07-08T12:00:01","date_gmt":"2013-07-08T17:00:01","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=719"},"modified":"2013-07-02T15:36:30","modified_gmt":"2013-07-02T20:36:30","slug":"eigshow-week-1","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2013\/07\/08\/eigshow-week-1\/","title":{"rendered":"eigshow, week 1"},"content":{"rendered":"<div class=\"content\"><!--introduction--><p>One of my all-time favorite MATLAB examples is <tt>eigshow<\/tt>.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/eigshowp_w1a.gif\" alt=\"\"> <\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#2a281988-0d04-481b-aa8c-e93fec6563c0\"><tt>eigshow<\/tt><\/a><\/li><li><a href=\"#6cca8b3e-96c6-4587-976d-207bcc21e343\">Ellipse<\/a><\/li><li><a href=\"#f96996aa-ef86-4137-b343-07584baff36c\">Line 'em up<\/a><\/li><li><a href=\"#58d514c8-7598-4e8b-a2be-a8a5d8c58d5d\">Eigenvectors<\/a><\/li><li><a href=\"#9ec3fc67-2aca-4e92-80d3-86de25b26b59\">A Second Matrix<\/a><\/li><li><a href=\"#77b2b408-3ab5-4f74-8b10-2b5c67348afa\">A Third Matrix<\/a><\/li><li><a href=\"#8eb9f600-b125-49c1-af2e-535714aee425\">More later<\/a><\/li><\/ul><\/div><h4><tt>eigshow<\/tt><a name=\"2a281988-0d04-481b-aa8c-e93fec6563c0\"><\/a><\/h4><p>The <tt>eigshow<\/tt> example has been part of MATLAB for a long time and has always been one of my favorites.<\/p><p>When you start <tt>eigshow<\/tt>, a 2-by-2 matrix is shown in the title bar. There is also a green vector <tt>x<\/tt> and a blue vector <tt>Ax<\/tt>, the image of <tt>x<\/tt> under the mapping induced by <tt>A<\/tt>.  The default values, shown in the animated gif above, are<\/p><pre class=\"codeinput\">format <span class=\"string\">rat<\/span>, format <span class=\"string\">compact<\/span>\r\nA = [1 3; 4 2]\/4\r\nx = [1; 0]\r\nAx = A*x\r\n<\/pre><pre class=\"codeoutput\">A =\r\n       1\/4            3\/4     \r\n       1              1\/2     \r\nx =\r\n       1       \r\n       0       \r\nAx =\r\n       1\/4     \r\n       1       \r\n<\/pre><h4>Ellipse<a name=\"6cca8b3e-96c6-4587-976d-207bcc21e343\"><\/a><\/h4><p>Now move <tt>x<\/tt> with the mouse.  <tt>x<\/tt> stays on the unit circle.  <tt>Ax<\/tt> goes wherever <tt>A<\/tt> takes <tt>x<\/tt>, generating the blue curve, an ellipse.<\/p><h4>Line 'em up<a name=\"f96996aa-ef86-4137-b343-07584baff36c\"><\/a><\/h4><p>Run <tt>eigshow<\/tt> yourself.  Don't just watch the animation. The instructions at the bottom of the screen say \" <b><tt>Make A*x parallel to x<\/tt><\/b> \". When you do this -- when the blue and green vectors are pointing in the same direction -- you have found an eigenvector.  The green vector is the eigenvector and the length of the overlapping blue vector is the eigenvalue.<\/p><h4>Eigenvectors<a name=\"58d514c8-7598-4e8b-a2be-a8a5d8c58d5d\"><\/a><\/h4><p>One eigenvector of this particular matrix is in the first or third quadrant, making an angle of roughly 60 degrees with the horizontal axis. The blue vector is longer than the green.  The eigenvalue is actually 5\/4.<\/p><p>The other eigenvector is obtained when the blue vector is pointing in the opposite direction from the green, because the eigenvalue is negative. The eigenvector is in the second or fourth quadrant, at an angle of about 45 degrees.  The eigenvalue is -1\/2.<\/p><p>Notice that the eigenvectors are not the major and minor axes of the ellipse.  This matrix is not quite symmetric.  If it were symmetric, the eigenvectors would be the axes.<\/p><h4>A Second Matrix<a name=\"9ec3fc67-2aca-4e92-80d3-86de25b26b59\"><\/a><\/h4><p>The title bar of <tt>eigshow<\/tt> is a pull-down menu that offers a dozen different matrices.  Our second example swaps the top two elements of the first example.<\/p><pre class=\"codeinput\">A = [3 1; 4 2]\/4\r\n<\/pre><pre class=\"codeoutput\">A =\r\n       3\/4            1\/4     \r\n       1              1\/2     \r\n<\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/eigshowp_w1b.gif\" alt=\"\"> <\/p><p>Now the aspect ratio of the ellipse is quite a bit larger. Both eigenvalues are positive. If you watch carefully, you can see that <tt>Ax<\/tt> goes around in the same direction as <tt>x<\/tt>.  Our first matrix has one negative eigenvalue and so <tt>x<\/tt> and <tt>Ax<\/tt> travel in opposite directions.<\/p><h4>A Third Matrix<a name=\"77b2b408-3ab5-4f74-8b10-2b5c67348afa\"><\/a><\/h4><p>Now choose the matrix that swaps the bottom two elements and flips one sign.<\/p><pre class=\"codeinput\">A = [3 1; -2 4]\/4\r\n<\/pre><pre class=\"codeoutput\">A =\r\n       3\/4            1\/4     \r\n      -1\/2            1       \r\n<\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/eigshowp_w1c.gif\" alt=\"\"> <\/p><p>Trying to make <tt>A*x<\/tt> parallel to <tt>x<\/tt> is frustrating.  You can't do it. More precisely, you would have to come off the page or screen to do it. This matrix does not have any real eigenvalues and eigenvectors. Its eigenvalues and eigenvectors are complex.<\/p><h4>More later<a name=\"8eb9f600-b125-49c1-af2e-535714aee425\"><\/a><\/h4><p>I plan to do more examples with <tt>eigshow<\/tt> in my next blog posting.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_8065825e14f54f45b3e2142faf8d0b5f() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='8065825e14f54f45b3e2142faf8d0b5f ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 8065825e14f54f45b3e2142faf8d0b5f';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2013 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_8065825e14f54f45b3e2142faf8d0b5f()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2013b<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2013b<br><\/p><\/div><!--\r\n8065825e14f54f45b3e2142faf8d0b5f ##### SOURCE BEGIN #####\r\n%% eigshow, week 1\r\n% One of my all-time favorite MATLAB examples is |eigshow|.\r\n%\r\n% <<eigshowp_w1a.gif>>\r\n%\r\n\r\n%% |eigshow|\r\n% The |eigshow| example has been part of MATLAB for a long time and\r\n% has always been one of my favorites. \r\n\r\n%%\r\n% When you start |eigshow|, a 2-by-2 matrix is shown in the title bar.\r\n% There is also a green vector |x| and a blue vector |Ax|, the image of |x|\r\n% under the mapping induced by |A|.  The default values, shown in the\r\n% animated gif above, are\r\n\r\nformat rat, format compact\r\nA = [1 3; 4 2]\/4\r\nx = [1; 0]\r\nAx = A*x\r\n\r\n%% Ellipse\r\n% Now move |x| with the mouse.  |x| stays on the unit circle.  |Ax| goes\r\n% wherever |A| takes |x|, generating the blue curve, an ellipse.\r\n\r\n%% Line 'em up\r\n% Run |eigshow| yourself.  Don't just watch the animation.\r\n% The instructions at the bottom of the screen say\r\n% \" *|Make A*x parallel to x|* \".\r\n% When you do this REPLACE_WITH_DASH_DASH when the blue and green vectors are pointing in the\r\n% same direction REPLACE_WITH_DASH_DASH you have found an eigenvector.  The green vector is the\r\n% eigenvector and the length of the overlapping blue vector is the eigenvalue.\r\n\r\n%% Eigenvectors\r\n% One eigenvector of this particular matrix is in the first or third quadrant,\r\n% making an angle of roughly 60 degrees with the horizontal axis.\r\n% The blue vector is longer than the green.  The eigenvalue is actually 5\/4.\r\n\r\n%%\r\n% The other eigenvector is obtained when the blue vector is pointing in\r\n% the opposite direction from the green, because the eigenvalue is negative.\r\n% The eigenvector is in the second or fourth quadrant, at an angle of about\r\n% 45 degrees.  The eigenvalue is -1\/2.\r\n\r\n%%\r\n% Notice that the eigenvectors are not the major and minor axes of the\r\n% ellipse.  This matrix is not quite symmetric.  If it were symmetric,\r\n% the eigenvectors would be the axes.  \r\n\r\n%% A Second Matrix\r\n% The title bar of |eigshow| is a pull-down menu that offers\r\n% a dozen different matrices.  Our second example swaps the top two elements\r\n% of the first example.\r\n\r\nA = [3 1; 4 2]\/4\r\n\r\n%%\r\n%\r\n% <<eigshowp_w1b.gif>>\r\n%\r\n\r\n%%\r\n% Now the aspect ratio of the ellipse is quite a bit larger.\r\n% Both eigenvalues are positive.\r\n% If you watch carefully, you can see that |Ax| goes around in the same\r\n% direction as |x|.  Our first matrix has one negative eigenvalue and so\r\n% |x| and |Ax| travel in opposite directions.\r\n\r\n%% A Third Matrix\r\n% Now choose the matrix that swaps the bottom two elements and flips one sign.\r\n\r\nA = [3 1; -2 4]\/4\r\n\r\n%%\r\n%\r\n% <<eigshowp_w1c.gif>>\r\n%\r\n\r\n%%\r\n% Trying to make |A*x| parallel to |x| is frustrating.  You can't do it.\r\n% More precisely, you would have to come off the page or screen to do it.\r\n% This matrix does not have any real eigenvalues and eigenvectors.\r\n% Its eigenvalues and eigenvectors are complex.\r\n\r\n%% More later\r\n% I plan to do more examples with |eigshow| in my next blog posting.\r\n\r\n##### SOURCE END ##### 8065825e14f54f45b3e2142faf8d0b5f\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/eigshowp_w1a.gif\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction--><p>One of my all-time favorite MATLAB examples is <tt>eigshow<\/tt>.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2013\/07\/08\/eigshow-week-1\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[13,6],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/719"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/users\/78"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/comments?post=719"}],"version-history":[{"count":8,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/719\/revisions"}],"predecessor-version":[{"id":727,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/719\/revisions\/727"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}