clear all
clc
tic
OmegaR=1
Delta=3*sqrt(3)
lambda = (sqrt(OmegaR^2+Delta^2))/2
TRonR =(2*pi)/(OmegaR)
TRoffR=(2*pi)/sqrt(OmegaR^2+Delta^2)
pi/lambda-TRoffR
nop=501;
tl= 0;    
tr= TRonR; 
step=(tr-tl)/(nop-1); % nm
for i=1:nop;
    t(i)=tl+step*(i-1);  
    P1onR(i)=cos((OmegaR/2)*t(i))^2;    
    P2onR(i)=sin((OmegaR/2)*t(i))^2;
    P1offR(i)= 1 + (OmegaR^2*(cos(2*lambda*t(i))-1))/(2*(OmegaR^2+Delta^2));
    P2offR(i)=(OmegaR^2)/(OmegaR^2+Delta^2)*sin(lambda*t(i))^2;
end
%plot(x,c,'k',x,y1,'b',x,y2,'r'); figure(gcf);
plot(t,P1onR,'k',t,P2onR,'b','LineWidth',2,'LineStyle','-'); hold on;
%legend('P_1(t)','P2(t)')
plot(t,P1offR,'r',t,P2offR,'g','LineWidth',2,'LineStyle','--') 
h = legend('$P_1(t)$ on Resonance','$P_2(t)$ on Resonance','$P_1(t)$ off Resonance','$P_2(t)$ off Resonance');
set(h,'Interpreter','latex','FontSize',10)
title({'Oscillations in a two-level system';'(On Resonance and Off Resonance)'})
xlabel('$t$(s)','Interpreter','latex','FontSize',16)
ylabel('probabilities','FontSize',16)
annotation('textbox',...
    [0.7 0.45 0.17 0.15],...
    'String',{'plotting with',['\Omega_R = ' num2str(OmegaR),' s^{-1}'],['\Delta = ' num2str(Delta),' s^{-1}']},...
    'FontSize',10,...
    'FontName','Arial',...
    'LineStyle','--',...
    'EdgeColor',[1 1 0],...
    'LineWidth',2,...
    'BackgroundColor',[0.9 0.9 0.9],...
    'Color',[0.84 0.16 0]);

hold off;
toc
