
% This program accompanies the book: "Introduction to Quantum Mechanics:
% A Time Dependent Perspective", by David Tannor (University Science Books, 2003).




% programme for analysing population transfer in STIRAP systems
%
a=[1 0 0]';
height=100;
width=1;
delta=1;
tmax=20;
tinit=0;
npoints=1000;
tdif=(tmax-tinit)./(npoints-1);
%
%
T=zeros(npoints,1);
Y=zeros(npoints,3);
B=zeros(npoints,9);
ompall=zeros(npoints,1);
omsall=zeros(npoints,1);
t=tinit;
for ind=1:npoints;
    T(ind)=t;
    oms=height./(cosh(width.*(t-6)).^2);
    omp=height./(cosh(width.*(t-9)).^2);
%
% next line changes pulse orders for Rabi solution
%
%    oms=height./(cosh(width.*(t-12)).^2);
%    omp=height./(cosh(width.*(t-2)).^2);
    omsall(ind)=oms;
    ompall(ind)=omp;
    H=i.*[0 omp 0;omp delta oms;0 oms 0];
    [U V]=eig(H);
%     a=U*(exp(diag(V).*tdif).*(inv(U)*a));
%     
% the above calculation of a is preferable because no calculation of the zeros in exp(V) is needed,
% however the formal calculation of a is below. Note the two diags - so that exp(0) in the off-diagonals 
% stay 0 and do not become 1.
%
%    a=(U*diag(diag(exp(V.*tdif)))*inv(U))*a
%  
    D=U*diag(diag(exp(V.*tdif)))*inv(U);
    a=D*a;
    B(ind,:)=transpose(D(:));
    Y(ind,:)=transpose(a);
    t=t+tdif;
end;
%
% printing pulses
%
plot(T,abs(Y).^2);
figure
plot(T,[ompall omsall]);
