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 = cos(t);

e1y = sin(t);

 

e2x = -sin(t);

e2y = cos(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';

 

e1 = [0 0;1 0];

e2 = [0 0;0 1];

e1 = e1';

e2 = e2';

 

x = x';

 

 

tx = m * x;

taxList = m * axList;

te1 = m * e1;

te2 = m * e2;

     

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

 

qx = e1(:,1:2);

quiver(qx(1),qx(2),qx(3),qx(4),'Color','red','LineWidth',2,'MaxHeadSize',0.15);

qx = e2(:,1:2);

quiver(qx(1),qx(2),qx(3),qx(4),'Color','blue','LineWidth',2,'MaxHeadSize',0.15);

 

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

 

qx = te1(:,1:2);

quiver(qx(1),qx(2),qx(3),qx(4),'Color','red','LineWidth',2,'MaxHeadSize',0.15);

qx = te2(:,1:2);

quiver(qx(1),qx(2),qx(3),qx(4),'Color','blue','LineWidth',2,'MaxHeadSize',0.15);

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

 

qx = te1(:,1:2);

quiver(qx(1),qx(2),qx(3),qx(4),'Color','red','LineWidth',2,'MaxHeadSize',0.15);

qx = te2(:,1:2);

quiver(qx(1),qx(2),qx(3),qx(4),'Color','blue','LineWidth',2,'MaxHeadSize',0.15);

 

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;