File:QHO-Fockstate1+2squeezed-animation.gif

Summary

Description
English: Animation of the probability distribution of the quantum wave function of a squeezed state in a Quantum harmonic oscillator consisting only of the first two energy eigenstates. The best squeezing reached is a reduction in standard deviation by a factor of with the initial wavefunction
Date
Source Own work
 
This plot was created with Matplotlib.
Category:PNG created with Matplotlib#QHO-Fockstate1+2squeezed-animation.gif
Author Geek3
Other versions QHO-Fockstate1+2squeezed-animation-color.gif (with colored phase)

Source Code

The plot was generated with Matplotlib.

Python Matplotlib source code
#!/usr/bin/python
# -*- coding: utf8 -*-

from math import *
import matplotlib.pyplot as plt
from matplotlib import animation
import numpy as np
from numpy.polynomial.hermite import Hermite
import os, sys

# image settings
fname = 'QHO-Fockstate1+2squeezed-animation'
plt.rc('path', snap=False)
plt.rc('mathtext', default='regular')
width, height = 300, 200
ml, mr, mt, mb = 35, 8, 22, 45
x0, x1 = -3.5, 3.5
y0, y1 = 0.0, 0.8
nframes = 60
fps = 20

def animate(nframe):
    print str(nframe) + ' ',; sys.stdout.flush()
    t = float(nframe) / nframes * 1.0
    
    ax.cla()
    ax.grid(True)
    ax.axis((x0, x1, y0, y1))
    
    # Definition of Fock-states in terms of Hermite functions:
    # https://en.wikipedia.org/wiki/Quantum_harmonic_oscillator
    # maximum squeezing is reached for phi=pi/6
    psi_fock = np.array([cos(pi/6), sin(pi/6)])
    a_hermite = [a * pi**-0.25 / sqrt(2.**n*factorial(n))
                 * e**(-1j * 2*pi * (n+0.5) * t) for n, a in enumerate(psi_fock)]
    # doc: http://docs.scipy.org/doc/numpy/reference/generated/numpy.polynomial.hermite.Hermite.html
    H = Hermite(a_hermite)
    
    x = np.linspace(x0, x1, int(ceil(1+w_px)))
    psi_x = np.exp(-x**2 / 2.0) * H(x)
    y = np.abs(psi_x)**2
    
    plt.plot(x, y, lw=2, color='#0000cc')
    ax.set_yticks(ax.get_yticks()[:-1])
    ax.set_yticklabels([l for l in ax.get_yticks() if l < y0+0.9*(y1-y0)])
    

# create figure and axes
plt.close('all')
fig, ax = plt.subplots(1, figsize=(width/100., height/100.))
bounds = [float(ml)/width, float(mb)/height,
          1.0 - float(mr)/width, 1.0 - float(mt)/height]
fig.subplots_adjust(left=bounds[0], bottom=bounds[1],
                    right=bounds[2], top=bounds[3], hspace=0)
w_px = width - (ml+mr) # plot width in pixels

# axes labels
fig.text(0.5 + 0.5 * float(ml-mr)/width, 4./height,
         r'$x\ \ [(\hbar/(m\omega))^{1/2}]$', ha='center')
fig.text(5./width, 1.0, '$|\psi|^2$', va='top')

# start animation
if 0 != os.system('convert -version > ' +  os.devnull):
    print 'imagemagick not installed!'
    # warning: imagemagick produces somewhat jagged and therefore large gifs
    anim = animation.FuncAnimation(fig, animate, frames=nframes)
    anim.save(fname + '.gif', writer='imagemagick', fps=fps)
else:
    # unfortunately the matplotlib imagemagick backend does not support
    # options which are necessary to generate high quality output without
    # framewise color palettes. Therefore save all frames and convert then.
    if not os.path.isdir(fname):
        os.mkdir(fname)
    fnames = []
    
    for frame in range(nframes):
        animate(frame)
        imgname = os.path.join(fname, fname + '{:03d}'.format(frame) + '.png')
        fig.savefig(imgname)
        fnames.append(imgname)
    
    # compile optimized animation with ImageMagick
    cmd = 'convert -loop 0 -delay ' + str(100 / fps) + ' '
    cmd += ' '.join(fnames) # now create optimized palette from all frames
    cmd += r' \( -clone 0--1 \( -clone 0--1 -fill black -colorize 100% \) '
    cmd += '-append +dither -colors 63 -unique-colors '
    cmd += '-write mpr:colormap +delete \) +dither -map mpr:colormap '
    cmd += '-alpha activate -layers OptimizeTransparency '
    cmd += fname + '.gif'
    os.system(cmd)
    
    for fnamei in fnames:
        os.remove(fnamei)
    os.rmdir(fname)

Licensing

I, the copyright holder of this work, hereby publish it under the following licenses:
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License.
Category:License migration redundant#QHO-Fockstate1+2squeezed-animation.gifCategory:GFDL#QHO-Fockstate1+2squeezed-animation.gif
w:en:Creative Commons
attribution
This file is licensed under the Creative Commons Attribution 3.0 Unported license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
Category:CC-BY-3.0#QHO-Fockstate1+2squeezed-animation.gif
You may select the license of your choice.
Category:Self-published work Category:Animations of quantum wave functions Category:1D quantum harmonic oscillators Category:Animated GIF files Category:Photos by User:Geek3 Category:Squeezed coherent state
Category:1D quantum harmonic oscillators Category:Animated GIF files Category:Animations of quantum wave functions Category:CC-BY-3.0 Category:GFDL Category:License migration redundant Category:PNG created with Matplotlib Category:Pages using deprecated source tags Category:Photos by User:Geek3 Category:Self-published work Category:Squeezed coherent state