the sinc function

In [1]:
from ipywidgets import StaticInteract, RangeWidget, RadioWidget

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

# here we define the function which depends on variables.
# one can define functions with as many variables as desired

def f(x,var):
    return np.sinc(x/var)**2

# this is the routine which calls the function f(x,var)
# and plots the variation with respect to var

def plot(var):
    fig, ax = plt.subplots(figsize=(4, 3),
                           subplot_kw={'axisbg':'#EEEEEE',
                                       'axisbelow':True})
    ax.grid(color='w', linewidth=2, linestyle='solid')
    x = np.linspace(-50, 50, 1001)
    ax.plot(x, f(x,var), lw=5, alpha=0.4, label=var)
    ax.set_xlim(-50, 50)
    ax.set_ylim(-0.1, 1.1)
    ax.legend(loc='upper right')
    return fig

# here we look at the function's dependence on the value of var.
# we can add any number of variables var1, var2 in the same way.
# the syntax in the RangeWidget is (start, end, increment)

StaticInteract(plot,var=RangeWidget(10, 100, 10))
Out[1]:
var:

the fraunhofer limit

for a rectangular window of length 20 units and width 10. all units are in 1/k

In [2]:
x, y = np.linspace(-10,10,101), np.linspace(-10,10,101)
z1, z2, z3, z4 = np.zeros([101,101]), np.zeros([101,101]), np.zeros([101,101]), np.zeros([101,101])

a = 0
for i in x:
    b = 0
    for j in y:
        z1[a][b] = ((np.sinc(20*i/20))**2)*((np.sinc(10*j/20))**2)
        z2[a][b] = ((np.sinc(20*i/50))**2)*((np.sinc(10*j/50))**2)
        z3[a][b] = ((np.sinc(20*i/100))**2)*((np.sinc(10*j/100))**2)
        z4[a][b] = ((np.sinc(20*i/200))**2)*((np.sinc(10*j/200))**2)
        b += 1
    a += 1
a = 0
In [3]:
plt.subplot(221)
plt.imshow(z1)
plt.xticks([])
plt.title('z = 20')
plt.subplot(222)
plt.imshow(z2)
plt.title('z = 50')
plt.xticks([])
plt.subplot(223)
plt.imshow(z3)
plt.title('z = 100')
plt.subplot(224)
plt.imshow(z4)
plt.title('z = 200')
Out[3]:
<matplotlib.text.Text at 0xb04d746c>

for a square window of length 10 units and width 10. all units are in 1/k

In [4]:
x, y = np.linspace(-10,10,101), np.linspace(-10,10,101)
z1, z2, z3, z4 = np.zeros([101,101]), np.zeros([101,101]), np.zeros([101,101]), np.zeros([101,101])

a = 0
for i in x:
    b = 0
    for j in y:
        z1[a][b] = ((np.sinc(10*i/20))**2)*((np.sinc(10*j/20))**2)
        z2[a][b] = ((np.sinc(10*i/50))**2)*((np.sinc(10*j/50))**2)
        z3[a][b] = ((np.sinc(10*i/100))**2)*((np.sinc(10*j/100))**2)
        z4[a][b] = ((np.sinc(10*i/200))**2)*((np.sinc(10*j/200))**2)
        b += 1
    a += 1
a = 0
In [5]:
plt.subplot(221)
plt.imshow(z1)
plt.xticks([])
plt.title('z = 20')
plt.subplot(222)
plt.imshow(z2)
plt.title('z = 50')
plt.xticks([])
plt.subplot(223)
plt.imshow(z3)
plt.title('z = 100')
plt.subplot(224)
plt.imshow(z4)
plt.title('z = 200')
Out[5]:
<matplotlib.text.Text at 0xb12d66ac>
In []: