%{
|-------------------------------------------------------------------------|
|                        DemoLabz Simulations                             |
|                  Bits Pilani K.K. Birla Goa Campus                      |
|-------------------------------------------------------------------------|
|                   Author Name:Kushagra Nigam                            |
|       Quantum Squeezed States Classical Oscillator Analogy              |
|-------------------------------------------------------------------------|
%}

%Code 
%Memory and Screen Refresh
clc
clear
%Variables and Limits
m=1;                            %Mass of Body in kg
k=100;                          %Spring Constant in N/m
omg=sqrt(k/m);                  %Natural Frequency in rad/s
A1=5;                           %Maximum displacement of oscillator 1 in m
A2=6;                           %Maximum displacement of oscillator 2 in m
A3=7;                           %Maximum displacement of oscillator 3 in m
%Initial Condition
xnot=4;
%Time and Position Limits and Increments (in sec. and m)
tinit=0;
tmax=100;    
incr=.01;
%Frame Counter
n=1;     
%Coordinates 
xp=zeros(1,100);                %To store previous position of oscillator
pp=zeros(1,100);                %To store previous momentum of oscillator
xo=0;                           %To store origin coordinates
po=0;                           %To store origin coordinates
%Axis Margins
marx=2;
marp=20;
for t=tinit:incr:tmax
    x1=A1*sin(omg*t + asin(xnot/A1));
    p1=A1*m*omg*cos(omg*t + asin(xnot/A1));
    xp1(n)=x1;
    pp1(n)=p1;
    
    x2=A2*sin(omg*t + asin(xnot/A2));
    p2=A2*m*omg*cos(omg*t + asin(xnot/A2));
    xp2(n)=x2;
    pp2(n)=p2;
    
    x3=A3*sin(omg*t + asin(xnot/A3));
    p3=A3*m*omg*cos(omg*t + asin(xnot/A3));
    xp3(n)=x3;
    pp3(n)=p3;
    
    subplot(3,1,1);
    plot(xp1,pp1,xo,po,'kx',x1,p1,'ro',xp2,pp2,x2,p2,'bo',xp3,pp3,x3,p3,'go','Linewidth',2,'Markersize',10);
    axis([-A3-marx A3+marx -A3*m*omg-marp A3*m*omg+marp])
    title('Phase Space Plot');
    xlabel('x->');
    ylabel('p->');
    grid ON
    
    subplot(3,1,2);
    plot(t,x1,'ro',t,x2,'bo',t,x3,'go','Linewidth',2,'Markersize',5);
    axis([0 tmax -A3-marx A3+marx])
    title('Position vs Time');
    xlabel('t->');
    ylabel('x->');
    grid ON
    
    subplot(3,1,3);
    plot(t,p1,'ro',t,p2,'bo',t,p3,'go','Linewidth',2,'Markersize',5);
    axis([0 tmax -A3*m*omg-marp A3*m*omg+marp])
    title('Momentum vs Time');
    xlabel('t->');
    ylabel('p->');
    grid ON
    
M(n) = getframe();
n=n+1;
end
%Play Movie
fps=100;
repet=100
movie(M,repet,fps)
%--------------------------------------------------------------------------
