clear all

%A=[1 3;1 -1];

D=diag([-1;-2]);
theta=pi/100;c=cos(theta);s=sin(theta);

u1=[1;0];
u2=[c;s];

u1'*u2
U=[u1,u2];
iU=inv(U);

A=U*D*iU;

dt=0.01;

T=2;
Nt=ceil(T/dt);

EA=expm(dt*A);

x0=u2;

for ia=1:400
    x0=randn(2,1);
    x0=x0/norm(x0);%these vector are distributed uniformly on the circle
    theta(ia)=atan2(x0(2),x0(1));
   
xt=x0;
E(1)=real(xt'*xt);
tt(1)=0;

for it=2:Nt
    tt(it)=(it-1)*dt;
    xt=EA*xt;
    %xt=expm(tt(it)*A)*x0;
    E(it)=real(xt'*xt);
end


figure(40)
semilogy(tt,E,'r','linewidth',2)
xlabel('$t$','Interpreter','latex')
ylabel('$E(t)$','Interpreter','latex')
grid on
set(gca,'Fontsize',24)
hold on
semilogy(tt,exp(-2*tt),'k',tt,exp(-4*tt),'k','linewidth',2)
drawnow


end

[Nth,th1]=hist(theta,50);

figure(56)
plot(th1,Nth,'b','linewidth',2)
ylim([0,max(Nth)])













