% Plot some vectors and examine what happens with the eigenvectors
clear
hold off

N = 1000;

% Generate N points uniformly distributed within a unit circle
xnorm = rand(1, N); % 0-1
xang = rand(1, N) * 2*pi; % 0-2pi

x(1, :) = cos(xang) .* sqrt(xnorm); % sqrt to put more points at higher norms
x(2, :) = sin(xang) .* sqrt(xnorm); % in order to produce a uniform distribution

A = [-1, 2;
     -2, 4];

[V, L] = eig(A);

y1 = V'*x;
y2 = L*V'*x;
y = A*x;

% Color plot is much slower, but prettier
coloridx = xang / (2*pi);
% scatter(y(1,:), y(2,:), [], coloridx); 

% Plot x, inv(V)*x, L*inv(V)*x, and V*L*inv(V)*x
subplot(2, 2, 1);
% plot(x(1,:), x(2,:), 'x');
scatter(x(1,:), x(2,:), [], coloridx); 
axis([-1, 1, -1, 1]);
axis equal
title('Original points');

subplot(2, 2, 2);
%plot(y1(1,:), y1(2,:), 'x');
scatter(y1(1,:), y1(2,:), [], coloridx); 
axis([-1, 1, -1, 1]);
axis equal
title('Rotated by V^{-1}');

subplot(2, 2, 3);
%plot(y2(1,:), y2(2,:), 'x');
scatter(y2(1,:), y2(2,:), [], coloridx); 
axis equal
title('Rotated + scaled by LV^{-1}');

subplot(2, 2, 4);
%plot(y(1,:), y(2,:), 'x');
scatter(y(1,:), y(2,:), [], coloridx); 
axis equal
title('Final Ax');

% Plot the eigenvectors on the final plot
hold on;
plot([0 L(1,1)*V(1,1)], [0 L(1,1)*V(2,1)], '-r', 'LineWidth', 2);
plot([0 L(2,2)*V(1,2)], [0 L(2,2)*V(2,2)], '-r', 'LineWidth', 2);

