%   -1- population tranfert  from 100% on |g> to  100% on |e>  
%       Bloch Sphere via chirped adiabitic control
%   -2- population tranfert from 100%on |g> to 50% on |g> and 50% on  |e>   
%       Bloch Sphere via chirped adiabitic control
% 
%  IHP course 
% mazyar.mirrahimi@inria.fr
% pierre.rouchon@mines-paristech.fr
% October 2010
clear all; 
%% population transfert  from |g> to [e>
Delta=0.2;a=0.6; b=0.3; eps=0.02;
t=pi/eps*[-0.25:0.005:1.5];nt=length(t);dt=t(2)-t(1);
M=[0 0.1 -1]'; Omega=[0 0 Delta+a]; 
figure(1); clf;
HM=quiver3(0,0,0,M(1),M(2),M(3),'linewidth',5,'MaxHeadSize',0.5); set(gca,'fontsize',12);
axis (1.05*[-1 1 -1 1 -1 1]);
title('Population transfert from |g> to |e> (M in blue and \Omega in red)','fontsize',16);
hold on ;
Homega=quiver3(0,0,0,Omega(1),Omega(2),Omega(3),'r','linewidth',2,'MaxHeadSize',0.5);
H3=plot3(0,0,0,'ok','MarkerSize',6,'linewidth',5);
pause; figure(1);
for it=1:nt
  s=max(0,min(pi,eps*t(it))); v=b*sin(s); w=a*cos(s);
  Omega=[v 0 Delta+w]';
  Rot=expm(dt*[0 -Delta-w 0;Delta+w 0 -v;0 v 0]);
  M=Rot*M;
  set(HM,'UData',M(1),'VData',M(2),'WData',M(3)); 
  set(Homega,'UData',Omega(1),'VData',Omega(2),'WData',Omega(3)); 
  pause(.05);
end
pause;
%% population tranfert from 100%on |g> to 50% on |g> and 50% on  |e> 
a=0.4;  eps=0.02;
t=pi/eps*[0.:0.002:1.];nt=length(t);dt=t(2)-t(1);
M=[0 0 -1]'; Omega=[0 0 0]; 
figure(2); clf;
HM=quiver3(0,0,0,M(1),M(2),M(3),'linewidth',5,'MaxHeadSize',0.5); set(gca,'fontsize',12);
axis (1.05*[-1 1 -1 1 -1 1]);
title('Population transfert from 100%|g> to 50%|g> and 50%|e>','fontsize',18);
hold on ;
Homega=quiver3(0,0,0,Omega(1),Omega(2),Omega(3),'r','linewidth',2,'MaxHeadSize',0.5);
H3=plot3(0,0,0,'ok','MarkerSize',6,'linewidth',5);
pause; figure(2)
for it=1:nt
  s=max(0,min(pi,eps*t(it))); v=a*(sin(pi-s)-sin(2*(pi-s))/2); w=a*(sin(s)-sin(2*s)/2);
  Omega=[v 0 w]';
  Rot=expm(dt*[0 -w 0;+w 0 -v;0 v 0]);
  M=Rot*M;
  set(HM,'UData',M(1),'VData',M(2),'WData',M(3)); 
  set(Homega,'UData',Omega(1),'VData',Omega(2),'WData',Omega(3)); 
  pause(.05);
end

return
