clear
% Specify Vertices - 
% Note: for unit square use 4 vertices [0 0; 1 0; 1 1; 0 1]
%       and change repmat value 3 to 4. 
v=[0 0; 1 0; 0.5 sqrt(3)/2 ];

% Draw Blue Triangle 
patch(v(:,1), v(:,2),'b');

% Set Scale of Axes
axis([-1 2 -1 2])
axis square

% Hold Figure to add next triangle
hold on

% Transform Triangle w = Av+b 
% Specify Transformations A = [a b; c d]
A=[0.5 0; 0 0.5];
b=[0 0.5];
w=A*v';
w=w'+repmat(b,3,1);

% Draw Red Triangle using RGB scaling
patch(w(:,1), w(:,2),[1 0 0]);
hold off

% Hold Figure to add next triangle
hold on

% Transform Triangle w = Av+b 
% Specify Transformations A = [a b; c d]
t=pi/6;
A=[cos(t) -sin(t); sin(t) cos(t)]*[0.5 0; 0 .5];
b=[0 0];
w=A*v';
w=w'+repmat(b,3,1);

% Draw Green Triangle using RGB scaling
patch(w(:,1), w(:,2),[0 1 0]);
hold off

% Eigenvalues
[V,D] = eig(A);
D