{"id":375,"date":"2017-09-14T12:01:32","date_gmt":"2017-09-14T15:01:32","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=375"},"modified":"2017-09-14T12:01:32","modified_gmt":"2017-09-14T15:01:32","slug":"eigshow-m","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/eigshow-m\/","title":{"rendered":"eigshow.m"},"content":{"rendered":"<pre>function eigshow(arg)\r\n%EIGSHOW Graphical demonstration of eigenvalues and singular values.\r\n%\r\n%   EIGSHOW presents a graphical experiment showing the effect on the\r\n%   the unit circle of the mapping induced by various 2-by-2 matrices.\r\n%   A pushbutton allows the choice of \"eig\" mode or \"svd\" mode.\r\n%\r\n%   In eig mode, the mouse can be used to move the vector x around the\r\n%   unit circle.  The resulting trajectory of A*x is plotted.  The object\r\n%   is to find vectors x so that A*x is parallel to x.  Each such x is an\r\n%   eigenvector of A.  The length of A*x is the corresponding eigenvalue.\r\n%\r\n%   In svd mode, the mouse moves two perpendicular unit vectors, x and y.\r\n%   The resulting A*x and A*y are plotted.  When A*x is perpendicular to\r\n%   A*y, then x and y are right singular vectors, A*x and A*y are\r\n%   multiples of left singular vectors, and the lengths of A*x and A*y\r\n%   are the corresponding singular values.\r\n%\r\n%   The figure title is a menu of selected matrices, including some\r\n%   with fewer than two real eigenvectors.  EIGSHOW(A) inserts A,\r\n%   which must be 2-by-2, in the menu.\r\n%\r\n%   Here are some questions to consider:\r\n%      Which matrices are singular?\r\n%      Which matrices have complex eigenvalues?\r\n%      Which matrices have double eigenvalues?\r\n%      Which matrices have eigenvalues equal to singular values?\r\n%      Which matrices have nondiagonal Jordan canonical forms?\r\n\r\n%   Copyright (c) 1984-98 by The MathWorks, Inc.\r\n%   $Revision: 1.2 $  $Date: 1997\/11\/21 23:25:37 $\r\n\r\nif nargin == 0;\r\n   initialize\r\nelseif arg == 0\r\n   action\r\nelseif arg &lt; 0\r\n   setmode(arg)\r\nelse\r\n   initialize(arg);\r\nend\r\n\r\n%------------------\r\n\r\nfunction initialize(arg)\r\n\r\nif nargin == 0\r\n   arg = 6;\r\nend\r\n\r\nif isequal(get(gcf,'tag'),'eigshow');\r\n   h = get(gcf,'userdata');\r\n   mats = h.mats;\r\nelse\r\n   set(gcf,'numbertitle','off','menubar','none')\r\n   h.svd = 0;\r\n   mats = {\r\n      '[5\/4 0; 0 3\/4]'\r\n      '[5\/4 0; 0 -3\/4]'\r\n      '[1 0; 0 1]'\r\n      '[0 1; 1 0]'\r\n      '[0 1; -1 0]'\r\n      '[1 3; 4 2]\/4'\r\n      '[1 3; 2 4]\/4'\r\n      '[3 1; 4 2]\/4'\r\n      '[3 1; -2 4]\/4'\r\n      '[2 4; 2 4]\/4'\r\n      '[2 4; -1 -2]\/4'\r\n      '[6 4; -1 2]\/4'\r\n      'randn(2,2)'};\r\nend\r\n\r\nif all(size(arg)==1)\r\n   if (arg &lt; length(mats))\r\n      mindex = arg;\r\n      A = eval(mats{mindex});\r\n   else\r\n      A = randn(2,2);\r\n      S = ['[' sprintf('%4.2f %4.2f; %4.2f %4.2f',A) ']'];\r\n      mindex = length(mats);\r\n      mats = [mats(1:mindex-1); {S}; mats(mindex)];\r\n   end\r\nelse\r\n   A = arg;\r\n   if isstr(A)\r\n      S = A;\r\n      A = eval(A);\r\n   else\r\n      S = ['[' sprintf('%4.2f %4.2f; %4.2f %4.2f',A) ']'];\r\n   end\r\n   if any(size(A) ~= 2)\r\n      error('Matrix must be 2-by-2')\r\n   end\r\n   mats = [{S};  mats];\r\n   mindex = 1;\r\nend\r\n\r\nclf\r\nif h.svd, t = 'svd \/ (eig)';\r\n    else, t = 'eig \/ (svd)';\r\nend\r\nuicontrol(...\r\n   'style','pushbutton', ...\r\n   'units','normalized', ...\r\n   'position',[.86 .60 .12 .06], ...\r\n   'string',t, ...\r\n   'value',h.svd, ...\r\n   'callback','eigshow(-1)');\r\nuicontrol(...\r\n   'style','pushbutton', ...\r\n   'units','normalized', ...\r\n   'position',[.86 .50 .12 .06], ...\r\n   'string','help', ...\r\n   'callback','helpwin eigshow')\r\nuicontrol(...\r\n   'style','pushbutton', ...\r\n   'units','normalized', ...\r\n   'position',[.86 .40 .12 .06], ...\r\n   'string','close', ...\r\n   'callback','close(gcf)')\r\nuicontrol(...\r\n   'style','popup', ...\r\n   'units','normalized', ...\r\n   'position',[.28 .92 .48 .08], ...\r\n   'string',mats, ...\r\n   'tag','mats', ...\r\n   'fontname','courier', ...\r\n   'fontweight','bold', ...\r\n   'fontsize',14, ...\r\n   'value',mindex, ...\r\n   'callback','eigshow(get(gco,''value''))');\r\n\r\ns = 1.1*max(1,norm(A));\r\naxis([-s s -s s])\r\naxis square\r\nxcolor = [0 .6 0];\r\nAxcolor = [0 0 .8];\r\nh.A = A;\r\nh.mats = mats;\r\nh.x = initv([1 0]','x',xcolor);\r\nh.Ax = initv(A(:,1),'Ax',Axcolor);\r\nif h.svd\r\n   h.y = initv([0 1]','y',xcolor);\r\n   h.Ay = initv(A(:,2),'Ay',Axcolor);\r\n   xlabel('Make A*x perpendicular to A*y','fontweight','bold')\r\n   set(gcf,'name','svdshow')\r\nelse\r\n   xlabel('Make A*x parallel to x','fontweight','bold')\r\n   set(gcf,'name','eigshow')\r\nend\r\nset(gcf,'tag','eigshow', ...\r\n   'userdata',h, ...\r\n   'windowbuttondownfcn', ...\r\n      'eigshow(0); set(gcf,''windowbuttonmotionfcn'',''eigshow(0)'')', ...\r\n   'windowbuttonupfcn', ...\r\n      'set(gcf,''windowbuttonmotionfcn'','''')')\r\n\r\n%------------------\r\n\r\nfunction h = initv(v,t,color)\r\nh.mark = line(v(1),v(2),'marker','.','erase','none','color',color);\r\nh.line = line([0 v(1)],[0 v(2)],'erase','xor','color',color);\r\nh.text = text(v(1)\/2,v(2)\/2,t,'fontsize',12,'erase','xor','color',color);\r\n\r\n%------------------\r\n\r\nfunction action\r\nh = get(gcf,'userdata');\r\npt = get(gca,'currentpoint');\r\nx = pt(1,1:2)';\r\nx = x\/norm(x);\r\nmovev(h.x,x);\r\nA = h.A;\r\nmovev(h.Ax,A*x);\r\nif h.svd\r\n   y = [-x(2); x(1)];\r\n   movev(h.y,y);\r\n   movev(h.Ay,A*y);\r\nend\r\n\r\n%------------------\r\n\r\nfunction movev(h,v)\r\nset(h.mark,'xdata',v(1),'ydata',v(2));\r\nset(h.line,'xdata',[0 v(1)],'ydata',[0 v(2)]);\r\nset(h.text,'pos',v\/2);\r\n\r\n%------------------\r\n\r\nfunction setmode(arg)\r\nh = get(gcf,'userdata');\r\nh.svd = ~h.svd;\r\nset(gcf,'userdata',h)\r\ninitialize(get(findobj(gcf,'tag','mats'),'value'))\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>function eigshow(arg) %EIGSHOW Graphical demonstration of eigenvalues and singular values. % % EIGSHOW presents a graphical experiment showing the effect on the % the unit circle of the mapping induced by various 2-by-2 matrices. % A pushbutton allows the choice of &#8220;eig&#8221; mode or &#8220;svd&#8221; mode. % % In eig mode, the mouse can be [&hellip;]<\/p>\n","protected":false},"author":22,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[],"tags":[],"class_list":["post-375","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/comments?post=375"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/375\/revisions"}],"predecessor-version":[{"id":376,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/375\/revisions\/376"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}