% % Linear transformations of the plane % disp('Create two random matrices A and B') pause % A=floor(5*rand(2,2)-2) B=floor(5*rand(2,2)-2) % pause format rational disp('Calculate the products C=A*B and D=B*A and the inverses Ainv and Binv') pause C=A*B D=B*A pause Ainv=eye(2)/A Binv=eye(2)/B pause disp('Check that these are indeed inverses:') pause disp('A*Ainv=') A*Ainv disp('Ainv*A=') Ainv*A disp('B*Binv=') B*Binv disp('Binv*B=') Binv*B pause disp('Next create a polygonal figure in the plane') cla reset xx=[0 1 1 0 0] yy=[0 0 1 1 0] disp('and plot the polygon.') disp('Rather than using the predefined colors, we play with RGB-values!') pause fill(xx,yy,[.3 .2 .9]) axis([-4,4,-4,4]) drawnow disp('Arrange the windows so that you can see both the figure and the command window.') hold on pause disp('Next calculate how A and B transform the points') pause pts=[xx;yy] Apts=A*pts Bpts=B*pts pause disp('and overlay the transformed polygons') plot(Apts(1,:),Apts(2,:),'c-') drawnow plot(Bpts(1,:),Bpts(2,:),'m-') drawnow disp('click on the figure window to see the overlaid polygons') pause disp('Verify that (A*B)*pts and A*(B*pts) are the same etc.') pause A*Bpts C*pts disp('Here the message is: Matrix multiplication corresponds to') disp('COMPOSITION of linear maps (transformations)') pause disp('To have some more fun, redo the above with your own polygon!') disp('For inspiration, look at the following ten distorted cats.') disp('You need to toggle between the command window and the figure') disp('window, most easily using the ALT-TAB key combination.') pause cla reset for i=1:10 catt drawnow pause end disp('Now it is your turn.')