% EigenPlay is a script which shows how eigenvectors and eigenvalues
% affect the matrix transformation

close all;
set(0,'DefaultFigureWindowStyle','docked')
figure;
L = 30;

%a = [1 2; 0 1];

cm = colormap(jet);
r = resample(cm(:,1),16,1);
g = resample(cm(:,2),16,1);
b = resample(cm(:,3),16,1);

% Do you want to see scaled iterates
	ScaleIt = 0;

% Random input, plus points along sub-dominant eigen-direction 
	K = 1024;
	X = -5+10*rand(1,K);
	Y = -5+10*rand(1,K);
	%X =   [X  linspace(-1,0,24)];
	%Y =  [Y linspace(1,0,24)];
	X0 = X;
	Y0 = Y;


for i = 1:1;

if i == 1 || ScaleIt
	% Because numerical erros were found to propagate with vectorized code
	for j = 1:length(X);
		N(j) = norm([X(j);Y(j)]);
	end

	if ScaleIt
		X = X./N;
		Y = Y./N;
	end

	if i  == 1;
		D = sortrows([X;Y;N]',3)';
	end
	
	scatter(D(1,:),D(2,:),30,[r g b],'filled');
	xlim([-L,L]);
	ylim([-L,L]);
	disp('Random Points before Transformation')
	pause
end

M = a*[D(1,:);D(2,:)];
X = M(1,:);
Y = M(2,:);
	for j = 1:length(X);
		N(j) = norm([X(j);Y(j)]);
	end
D = [X;Y;N];

scatter(D(1,:),D(2,:),30,[r g b],'filled');

%if i > 30
%	pause
%	D(:,999:end)
%end
xlim([-L,L]);
ylim([-L,L]);
disp('..... after transformation by ');
a
pause;
end

disp('EigenVectors and EigenValues')
[V,L] = eig(a)
pause

