%Matrix times circle equal ellipse

clear;
lw2=2.5;
lw1=1.5;
figure(1);clf

A=0.75*[2 0.5 ;  1.5 1]
%A=1.2*rand(2,2)
mya=linspace(0,2*pi,200);
N=200;mya=linspace(0,2*pi,N);
xC=1*cos(mya);
yC=1*sin(mya);
xE=[];yE=[];for ii=1:N;V0=[xC(ii);yC(ii)];V1=A*V0;xE(ii)=V1(1);yE(ii)=V1(2);end
plot(xC,yC,'-',xE,yE,'-','LineWidth',lw1)
axis equal
hold on

[VA,EA]=eig(A);
EA=diag(EA);
if(abs(EA(1))<abs(EA(2))) EA=flipud(EA); VA=fliplr(VA);end
if(VA(1,1)<0) VA(:,1)=-VA(:,1);end
if(VA(1,2)>0) VA(:,2)=-VA(:,2);end
plot([0 abs(EA(1))*VA(1,1)],[0 abs(EA(1))*VA(2,1)],'k-','LineWidth',lw1)
plot([0 abs(EA(2))*VA(1,2)],[0 abs(EA(2))*VA(2,2)],'k-','LineWidth',lw1)
VA,EA

M=A*A.'
[VM,EM]=eig(M);
EM=diag(EM);
if(abs(EM(1))<abs(EM(2))) EM=flipud(EM); VM=fliplr(VM);end
if(VM(1,1)<0) VM(:,1)=-VM(:,1);end
if(VM(1,2)>0) VM(:,2)=-VM(:,2);end
plot([0 sqrt(abs(EM(2)))*VM(1,2)],[0 sqrt(abs(EM(2)))*VM(2,2)],'m-','LineWidth',lw2)
plot([0 sqrt(abs(EM(1)))*VM(1,1)],[0 sqrt(abs(EM(1)))*VM(2,1)],'m-','LineWidth',lw2)
VM,EM,sqrt_EM=sqrt(EM),

