Matrix  - Basis Transform

 Followings are the code that I wrote in Octave to creates all the plots shown in this page. You may copy these code and play with these codes. Change variables and try yourself until you get your own intuitive understanding.   < Code 1 >   n = 0; t = n * 2*pi/40 + pi/2;   e1x = 1; e1y = 0;   e2x = cos(t); e2y = sin(t);   m = [e1x e2x; ...      e1y e2y];            x = []; for i = -10:10    x = [x ; [-10 i;10 i]];    end   for j = -10:10    x = [x ; [j -10;j 10]];    end   axList = [[-10 0;10 0];[0 -10;0 10]]; axList = axList';   pty1 = []; % point on +y axis for i = 0:0.25:2;    pty1 = [pty1 ; [0 i]];   end   pty2 = []; % point on -y axis for i = -2:0.25:0;    pty2 = [pty2 ; [0 i]];   end   ptx1 = []; % point on +x axis for i = 0:0.25:2;    ptx1 = [ptx1 ; [i 0]];   end   ptx2 = []; % point on -x axis for i = -2:0.25:0;    ptx2 = [ptx2 ; [i 0]];   end   ptph1 = []; % point on phase 1 for j = 0.25:0.25:2; for i = 0.25:0.25:2;    ptph1 = [ptph1 ; [i j]];   end end   ptph2 = []; % point on phase 2 for j = 0.25:0.25:2; for i = -2:0.25:-0.25;    ptph2 = [ptph2 ; [i j]];   end end   ptph3 = []; % point on phase 3 for j = -2:0.25:-0.25; for i = -2:0.25:-0.25;    ptph3 = [ptph3 ; [i j]];   end end   ptph4 = []; % point on phase 4 for j = -2:0.25:-0.25; for i = 0.25:0.25:2;    ptph4 = [ptph4 ; [i j]];   end end   x = x'; pty1 = pty1'; pty2 = pty2'; ptx1 = ptx1'; ptx2 = ptx2'; ptph1 = ptph1'; ptph2 = ptph2'; ptph3 = ptph3'; ptph4 = ptph4';     tx = m * x; taxList = m * axList; tpty1 = m * pty1; tpty2 = m * pty2; tptx1 = m * ptx1; tptx2 = m * ptx2; tptph1 = m * ptph1; tptph2 = m * ptph2; tptph3 = m * ptph3; tptph4 = m * ptph4;         hFig = figure(1,'Position',[300 300 850 500]);        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% subplot(2,3,[1 3]);   hold on;   plot([0.0],[0.0]);   x0 = 0.5-0.14; y0 = 1.0-0.7;   text(x0+0.0,y0,"M = ",'FontSize',14,'color','black');   x0 = 0.42; y0 = -0.7;   tStr = sprintf('%0.04f    %0.04f\n%0.04f    %0.04f', ...                m(1,1),m(1,2),...                m(2,1),m(2,2));   text(x0+0.005,y0+1.0,tStr,'FontSize',14,'color','black'); line([x0-0.01 x0-0.01],[y0+0.8 y0+1.2],'LineWidth',1,'Color','black'); line([x0+0.20 x0+0.20],[y0+0.8 y0+1.2],'LineWidth',1,'Color','black');     axis([0.0 1.01 0 1.2]); set(gca,'Visible','off'); hold off;   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% subplot(2,3,4);      hold on; for i = 1:length(x)/2    lx = x(:,2*i-1:2*i);    line(lx(1,:),lx(2,:),'Color','black'); end   ##for i = 1:length(axList)/2 ##   lx = axList(:,2*i-1:2*i); ##   line(lx(1,:),lx(2,:),'Color','green','LineWidth',1); ##end   plot(pty1(1,:),pty1(2,:),'bo','MarkerFaceColor',[0 0 1],'MarkerSize',3); plot(pty2(1,:),pty2(2,:),'co','MarkerFaceColor',[0 1 1],'MarkerSize',3); plot(ptx1(1,:),ptx1(2,:),'ro','MarkerFaceColor',[1 0 0],'MarkerSize',3); plot(ptx2(1,:),ptx2(2,:),'mo','MarkerFaceColor',[1 0 1],'MarkerSize',3);   plot(ptph1(1,:),ptph1(2,:),'go','MarkerFaceColor',[0 1 0],'MarkerSize',3); plot(ptph2(1,:),ptph2(2,:),'yo','MarkerFaceColor',[1 1 0],'MarkerSize',3); plot(ptph3(1,:),ptph3(2,:),'ko','MarkerFaceColor',[0 0 0],'MarkerSize',3); plot(ptph4(1,:),ptph4(2,:),'bo','MarkerFaceColor',[0 0 1],'MarkerSize',3);   axis([-4 4 -4 4]); set(gca,'xticklabel',[]);set(gca,'yticklabel',[]); set(gca,'xtick',[]);set(gca,'ytick',[]); tStr = sprintf('[A] : orignal coordinate \nwith basis vectors'); title(tStr); daspect([1 1]); box on; hold off;     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% subplot(2,3,5);      hold on; for i = 1:length(x)/2    lx = x(:,2*i-1:2*i);    line(lx(1,:),lx(2,:),'Color','black'); end   ##for i = 1:length(axList)/2 ##   lx = axList(:,2*i-1:2*i); ##   line(lx(1,:),lx(2,:),'Color','green','LineWidth',2); ##end   plot(tpty1(1,:),tpty1(2,:),'bo','MarkerFaceColor',[0 0 1],'MarkerSize',3); plot(tpty2(1,:),tpty2(2,:),'co','MarkerFaceColor',[0 1 1],'MarkerSize',3); plot(tptx1(1,:),tptx1(2,:),'ro','MarkerFaceColor',[1 0 0],'MarkerSize',3); plot(tptx2(1,:),tptx2(2,:),'mo','MarkerFaceColor',[1 0 1],'MarkerSize',3);   plot(tptph1(1,:),tptph1(2,:),'go','MarkerFaceColor',[0 1 0],'MarkerSize',3); plot(tptph2(1,:),tptph2(2,:),'yo','MarkerFaceColor',[1 1 0],'MarkerSize',3); plot(tptph3(1,:),tptph3(2,:),'ko','MarkerFaceColor',[0 0 0],'MarkerSize',3); plot(tptph4(1,:),tptph4(2,:),'bo','MarkerFaceColor',[0 0 1],'MarkerSize',3);   tStr = sprintf('[B] : orignal coordinate \nwith colum vectors of M'); title(tStr);   axis([-4 4 -4 4]); set(gca,'xticklabel',[]);set(gca,'yticklabel',[]); set(gca,'xtick',[]);set(gca,'ytick',[]); daspect([1 1]); box on; hold off;     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% subplot(2,3,6);      hold on; for i = 1:length(x)/2    lx = tx(:,2*i-1:2*i);    line(lx(1,:),lx(2,:),'Color','black'); end   ##for i = 1:length(taxList)/2 ##   lx = taxList(:,2*i-1:2*i); ##   line(lx(1,:),lx(2,:),'Color','green','LineWidth',2); ##end   plot(tpty1(1,:),tpty1(2,:),'bo','MarkerFaceColor',[0 0 1],'MarkerSize',3); plot(tpty2(1,:),tpty2(2,:),'co','MarkerFaceColor',[0 1 1],'MarkerSize',3); plot(tptx1(1,:),tptx1(2,:),'ro','MarkerFaceColor',[1 0 0],'MarkerSize',3); plot(tptx2(1,:),tptx2(2,:),'mo','MarkerFaceColor',[1 0 1],'MarkerSize',3);   plot(tptph1(1,:),tptph1(2,:),'go','MarkerFaceColor',[0 1 0],'MarkerSize',3); plot(tptph2(1,:),tptph2(2,:),'yo','MarkerFaceColor',[1 1 0],'MarkerSize',3); plot(tptph3(1,:),tptph3(2,:),'ko','MarkerFaceColor',[0 0 0],'MarkerSize',3); plot(tptph4(1,:),tptph4(2,:),'bo','MarkerFaceColor',[0 0 1],'MarkerSize',3);   axis([-4 4 -4 4]); set(gca,'xticklabel',[]);set(gca,'yticklabel',[]); set(gca,'xtick',[]);set(gca,'ytick',[]); tStr = sprintf('[C] : transformed coordinate \nwith basis on the new coordinate'); title(tStr); daspect([1 1]); box on; hold off;