## Gaussian Wave Packet Widget


```python
# setup 
import numpy as np
import sympy as sp
sp.init_printing(use_latex='mathjax')

import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = (20, 20)  # (width, height)
plt.rcParams['font.size'] = 14
plt.rcParams['legend.fontsize'] = 16
from matplotlib import patches

#get_ipython().magic('matplotlib')  # separate window
get_ipython().magic('matplotlib inline') # inline plotting

from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets

def packet(sigma):
    numks = 200
    spacing = 1
    ksarr = np.arange(1, numks+1, spacing) # wavenumbers go from 1 to numks
    Aks = np.exp(-((ksarr-numks/2)/np.sqrt(2)/sigma)**2) # a gaussian centered 
    ksarr = ksarr * 1e5
    sigma = sigma * 1e5
    
    xs = np.arange(-0.5, 0.5, 1/numks) # The x values for our sine waves.
    xs = xs * 1e-5
    kxs = np.ones((numks,numks)) # Create a matrix for kx values to simplify calculations later.
    kxs = kxs[:,0:numks]*xs # Fill the kx matrix with x values along the rows.
    kxs = kxs[0:numks, :].T*ksarr # Multiply each column by its appropriate k value.
    arrlen = np.size(kxs)
    Axs = np.zeros((numks,numks)) # Create a matrix for the sine waves.
    Axs[:,0:numks]=Aks*np.sin(kxs) # Fill the matrix with the appropriate sine waves.
    onesies = np.ones(numks)
    waves = np.matmul(Axs, onesies) 
    
    plt.figure(1)
    plt.rcParams.update({'font.size': 20})
    plt.rcParams.update({'legend.fontsize' : 24})
    plt.subplot(311)
    plt.plot(ksarr, Aks)
    plt.title('Wavenumber Distribution')
    plt.xlabel('k (1/m)')
    plt.ylabel('A(k)')
    plt.subplot(312)
    plt.plot(xs,Axs[:,:])
    plt.title('The individual waves in creating the packet')
    plt.xlabel('x (m)')
    plt.ylabel('Amplitude')
    plt.subplot(313)
    plt.plot(xs, waves)
    plt.title('The wave packet')
    plt.xlabel('x (m)')
    plt.ylabel('Amplitude')
    plt.subplots_adjust(top=4, bottom=0.01, left=0.1, right=3.0, hspace=0.25, wspace=0.1)
    plt.show()
    

interact(packet, sigma=widgets.IntSlider(min=5,max=50,step=5,value=25));
```


    A Jupyter Widget



```python

```


```python

```


```python

```

f59ee3aa68d888aacc53d5db87c310efeff4f34c
ipynb
Jupyter Notebook
GaussianWavePackets.ipynb
guygastineau/Jupyter
5d97e1a57cc812e1131f1d39edbd6b15341f38ed
MIT
GaussianWavePackets.ipynb
guygastineau/Jupyter
5d97e1a57cc812e1131f1d39edbd6b15341f38ed
MIT
2018-08-06T17:55:54.000Z
2018-08-07T18:47:52.000Z
GaussianWavePackets.ipynb
guygastineau/Jupyter
5d97e1a57cc812e1131f1d39edbd6b15341f38ed
MIT
2018-08-06T17:39:08.000Z
2018-08-06T17:39:08.000Z
Qwen/Qwen-72B
1. YES
2. YES