% Brief 2-by-2 Matrix Tutorial % NEUR 1680 Spring 2008 %% random 2 by 2 matrix clear W = rand(2,2) % Note: entries are between 0 and 1 %% matrices are generalized numbers: % they can be worked ON: addition, multiplication, inverse... W_inverse = inv(W) eye(2)/W W^-1 W.^-1 W*W_inverse W_inverse*W det(W) % determinant has to be nonzero for matrix to be invertible % is non-zero with probability 1 for random matrix % create matrices with 0 determinant... % characterize such matrices... %% matrix operates on random vector % Matrices can also be used as OPERATORS acting on vectors % As such, a matrix is a LINEAR transformation of the plane u = rand(2,1) - [.5;.5]; % Note: entries are between -.5 and .5 v = W*u; figure(1) plot(u(1),u(2),'b*',v(1),v(2),'r*','markersize',10) axis([-1 1 -1 1]) axis square grid legend('original', 'transformed') %% matrix operates on cursor-defined vectors % choose your input vectors in "interesting" ways: lines, squares, circles,... % click in gray area to terminate close(1) u = [0;0]; figure(1) axis([-1 1 -1 1]) axis square grid hold on while abs(u) <= 1 u = ginput(1)'; v = W*u; plot(u(1),u(2),'b*',v(1),v(2),'r*','markersize',10) legend('original', 'transformed') end hold off % based on your observations, characterize the matrix as a geometric transformation... %% reflection about x-axis W = [1 0 0 -1]; %% reflection about y-axis W = [ ]; %% clockwise rotation about the origin theta = pi/3; W = [cos(theta) sin(theta) -sin(theta) cos(theta)]; % compute inverse and determinant... %% reflection about first diagonal W = [ ]; %% how would you characterize the following transformation? W = [1 0 2 1]; %% eigenstuff [V,D] = eig(W); % eigenvalues and eigenvectors of matrix disp('eigenvalues:') disp(num2str(D(logical(eye(2)))')) disp('eigenvectors:') disp(num2str(V)) %% random SYMMETRIC 2 by 2 matrix clear W = rand(2,2); W = .5*(W + W'); % Note: entries are still between 0 and 1 % what can you say of its eigenvalues and eigenvectors? % why are symmetric matrices important in models of Hebbian plasticity?