simulate: light double slit experiment

a simple program in Python 3 to simulate the double-slit experiment for light.

The program generates an interference pattern by calculating the intensity of the light at each point on a screen behind the slits. The program assumes that the light is monochromatic and that the slits are equally spaced and of equal width.

Here’s the code:

pythonCopy codeimport numpy as np
import matplotlib.pyplot as plt

# Constants
wavelength = 500e-9  # meters
slit_width = 100e-6  # meters
slit_spacing = 500e-6  # meters
screen_distance = 1  # meters
screen_width = 0.1  # meters
screen_resolution = 1000

# Calculate the spatial frequency of the interference pattern
spatial_frequency = 2 * np.pi / wavelength * screen_distance / slit_spacing

# Calculate the coordinates of the screen
screen_coords = np.linspace(-screen_width / 2, screen_width / 2, screen_resolution)

# Calculate the intensity at each point on the screen
intensity = np.zeros_like(screen_coords)
for i, x in enumerate(screen_coords):
    path_difference = np.sqrt((x - slit_spacing / 2) ** 2 + screen_distance ** 2) - np.sqrt(
        (x + slit_spacing / 2) ** 2 + screen_distance ** 2)
    intensity[i] = (np.sin(spatial_frequency * path_difference / 2) / (spatial_frequency * path_difference / 2)) ** 2

# Normalize the intensity so that the maximum value is 1
intensity /= np.max(intensity)

# Plot the interference pattern
plt.plot(screen_coords, intensity)
plt.xlabel('Position on screen (m)')
plt.ylabel('Normalized intensity')
plt.show()

You can adjust the constants at the top of the program to change the parameters of the experiment, such as the wavelength of the light, the width and spacing of the slits, and the distance and size of the screen. The program uses NumPy and Matplotlib to perform the calculations and plot the interference pattern, respectively.

I hope this helps! Let me know if you have any questions.

Leave a Comment