% % Graphical illustration of matrix norms, 16.2.2022 % % input: % A - 2x2 matrix with real nonzero eigenvalues % inorm - indicator of the used norm: % 1 = column, 2 = Eucliedan, 'inf' = row % % output: % fig. 1 - before transformation: % unit "circle" (blue) % eigenvectors (red) % fig. 2 - after transformation % radius of the dashed circle is spectral radius of A % "radius" of the green "circle" is norm of A close all clear all inorm = 2; % 1 = column, 2 = Eucliedan, 'inf' = row A = [1 0.5; 2 -1.5]; % general transformation, real eigenv. % A = [ 3 -1; -1 2]; % symmetric transformation % A = [ 0.9 0.6; 0 0.6]; % real eigenv., ro < 1, norm > 1 % A = [ 1 1; 0 1]; % shear % A = [1 -1; 1 2]; % general transformation, imag. eigenv. % X - unit "circle" (depends on norm) if inorm == 2 t = linspace(0,2*pi,40); X = [sin(t);cos(t)]; elseif inorm == 1 X = [1 0 -1 0 1; 0 1 0 -1 0]; else X = [-1 1 1 -1 -1; -1 -1 1 1 -1]; end plot(X(1,:),X(2,:),'linewidth',2) axis equal; axis([ -1.3 1.3 -1.1 1.1 ]) hold on; % V - eigenvectors, E - eigenvalues of A [V,E] = eig(A); realV = isreal(V); if realV % plot the (unit norm) eigenvectors V1 = V(:,1); V2 = V(:,2); d1 = norm(V1,inorm); d2 = norm(V2,inorm); UP = [ [0;0] V1/d1, [0;0] V2/d2 ]; plot(UP(1,:),UP(2,:),'r','linewidth',2) else disp('eigenvectors are imaginary') end figure(2); % unit "circle" plot(X(1,:),X(2,:), '--','linewidth',2) axis equal; hold on % "circle" of the size of the given matrix norm nr = norm(A, inorm); plot(nr*X(1,:),nr*X(2,:), 'g','linewidth',2) plot([nr,0], [0,0], 'g','linewidth',2) % spectral radius "circle" disp('eigenvalues:'); disp(num2str(diag(E))); s = max(abs(diag(E))); plot(s*X(1,:),s*X(2,:), '--k','linewidth',2) plot([s,0], [0,0], '--k','linewidth',2) % transformation of the unit "circle" B = A*X; plot(B(1,:),B(2,:),'linewidth',2) if realV % plot transformation of the eigenvectors UP = A*UP; plot(UP(1,:),UP(2,:),'r','linewidth',2) end %%%%%%%%%%%%%%%%%%%%%%%%%