t = linspace(0, 2*pi); r = 1; x = r*cos(t); y = r*sin(t); figure('name', 'Linear Transform', 'NumberTitle', 'off'); plot(x, y, '.'); limit = 2*[-r r -r r]; axis(limit); axis image; % Roatation matrix theta = pi/3; A = [cos(theta) -sin(theta); sin(theta) cos(theta)]; % Mirror matrix theta = pi/3; A = [cos(2*theta) sin(2*theta); sin(2*theta) -cos(2*theta)]; % Random matrix A = rand(2); [eig_vec, eig_value] = eig(A); eig_vec1 = eig_vec(:, 1); eig_vec2 = eig_vec(:, 2); fprintf('The linear transform is represented by matrix A:\n'); disp(A); if isreal(eig_value), fprintf('The first eigen vector is:\n'); fprintf('%g\n', eig_vec1); fprintf('The second eigen vector is:\n'); fprintf('%g\n', eig_vec2); fprintf('The first eigen value is: %g\n', eig_value(1,1)); fprintf('The second eigen value is: %g\n', eig_value(2,2)); else fprintf('The eigen vectors are complex.\n'); fprintf('The first eigen value is: %g + j*%g\n', ... real(eig_value(1,1)), imag(eig_value(1,1))), fprintf('The second eigen value is: %g + j*%g\n', ... real(eig_value(2,2)), imag(eig_value(2,2))), end arrow_x = 1+[-1 0 nan -0.15 0 -0.15]; arrow_y = [0 0 nan 0.15 0 -0.15]; arrow = arrow_x + j*arrow_y; inputH = line(real(arrow), imag(arrow), ... 'linewidth', 2, 'erase', 'xor', 'color', 'c', 'clip', 'off'); tmp = A*[arrow_x; arrow_y]; tmp = tmp(1,:)'+j*tmp(2,:)'; outputH = line(real(tmp), imag(tmp), ... 'linewidth', 2, 'erase', 'xor', 'color', 'm', 'clip', 'off'); % Plot the arrows for eigen vectors if isreal(eig_value), eig_arrow1 = arrow*exp(j*angle(eig_vec1(1)+j*eig_vec1(2))); eig_arrow2 = arrow*exp(j*angle(eig_vec2(1)+j*eig_vec2(2))); line(real(eig_arrow1), imag(eig_arrow1), 'color', 'g'); line(real(eig_arrow2), imag(eig_arrow2), 'color', 'g'); text(eig_vec1(1)/2, eig_vec1(2)/2, '1', 'horizon', 'center'); text(eig_vec2(1)/2, eig_vec2(2)/2, '2', 'horizon', 'center'); end xlabel('Click anywhere to drag the input vector.'); title('green: eigenvectors, cyan: input vector, magenta: output vector.'); AxisH = gca; FigH = gcf; % The following is for animation % action when button is first pushed down action1 = ['curr_info=get(AxisH, ''currentPoint'');', ... 'pointer=curr_info(1,1)+j*curr_info(1,2);', ... 'input_arrow = arrow*exp(j*angle(pointer));', ... 'input_arrow = arrow*pointer;', ... 'set(inputH, ''xdata'', real(input_arrow), ''ydata'', imag(input_arrow));', ... 'tmp=A*curr_info(1,1:2)'';', ... 'tmp = tmp(1)+j*tmp(2);', ... 'output_arrow = arrow*exp(j*angle(tmp));', ... 'output_arrow = arrow*tmp;', ... 'set(outputH, ''xdata'', real(output_arrow), ''ydata'', imag(output_arrow));']; % actions after the mouse is pushed down action2 = action1; % action when button is released action3 = action1; % temporary storage for the recall in the down_action set(AxisH,'UserData',action2); % set action when the mouse is pushed down down_action=[ ... 'set(FigH,''WindowButtonMotionFcn'',get(AxisH,''UserData''));' ... action1]; set(FigH,'WindowButtonDownFcn',down_action); % set action when the mouse is released up_action=[ ... 'set(FigH,''WindowButtonMotionFcn'','' '');', action3]; set(FigH,'WindowButtonUpFcn',up_action);