Skip to content

Commit 6ae4a0f

Browse files
committed
finding different diffraction parameters
1 parent 0177ae1 commit 6ae4a0f

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

physics/diffraction.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
import math
3+
4+
5+
6+
def check_min_intensity(slit_width = 1,diff_angle=0, wavelength=100):
7+
"""
8+
Checks for the condition of minimum intensity in a diffraction pattern.
9+
10+
Args:
11+
slit_width (float): The width of the slit in millimeters.
12+
diff_angle (float): The diffraction angle in radians.
13+
wavelength (float): The wavelength of light in nanometers.
14+
15+
Returns:
16+
bool: True if minimum intensity is met, otherwise False.
17+
18+
>>> check_min_intensity(4, 0.25, 300)
19+
False
20+
>>> check_min_intensity(1, 0.0001, 100)
21+
True
22+
"""
23+
wavelength *= 10**-6
24+
n_val = round(slit_width*(diff_angle)/wavelength,5)
25+
r_val = True if (n_val-math.floor(n_val)==0) else False
26+
return r_val
27+
28+
def check_max_intensity(slit_width=1,diff_angle=0,wavelength=100):
29+
"""
30+
Checks for the condition of maximum intensity in a diffraction pattern.
31+
32+
Args:
33+
slit_width (float): The width of the slit in millimeters.
34+
diff_angle (float): The diffraction angle in radians.
35+
wavelength (float): The wavelength of light in nanometers.
36+
37+
Returns:
38+
bool: True if maximum intensity is met, otherwise False.
39+
40+
>>> check_max_intensity(1, 0.001, 100)
41+
False
42+
>>> check_max_intensity(1, 0.00005, 100)
43+
True
44+
"""
45+
wavelength *=10**-6
46+
n_val = round(((2*slit_width*diff_angle)-wavelength)/(2*wavelength),4)
47+
r_val = True if (n_val-math.floor(n_val)==0) else False
48+
return r_val
49+
50+
def intensity_single_slit(slit_width=1,diff_angle=0,wavelength=100):
51+
"""
52+
Computes the intensity for a single slit diffraction pattern.
53+
54+
Args:
55+
slit_width (float): The width of the slit in millimeters.
56+
diff_angle (float): The diffraction angle in radians.
57+
wavelength (float): The wavelength of light in nanometers.
58+
59+
Returns:
60+
str: The intensity of the diffraction pattern.
61+
62+
>>> intensity_single_slit(1, 0.0005, 100)
63+
'0.9999999999177533 I0'
64+
"""
65+
beta = math.pi*slit_width*(math.sin(diff_angle)/wavelength)
66+
i_coeff = (math.sin(beta)/beta)**2
67+
return "{coeff} I0".format(coeff=i_coeff)
68+
69+
def intensity_double_slit(path_diff=0,intensity_max="I0"):
70+
"""
71+
Computes the intensity for a double slit diffraction pattern.
72+
73+
Args:
74+
path_diff (float): The path difference in the two waves.
75+
intensity_max (str or int): The maximum intensity.
76+
77+
Returns:
78+
str or float: The intensity of the diffraction pattern.
79+
80+
>>> intensity_double_slit(0, 1)
81+
4.0
82+
>>> intensity_double_slit(0.001, 1)
83+
3.999999000000084
84+
>>> intensity_double_slit(0)
85+
'4.0 I0'
86+
"""
87+
r_val = 4*intensity_max*(math.cos(path_diff/2))**2 if (type(intensity_max)==type(0)) else "{coeff} I0".format(coeff=(4*(math.cos(path_diff/2)**2)))
88+
return r_val
89+
90+
if(__name__=="__main__"):
91+
import doctest
92+
doctest.testmod()
93+
#pass

0 commit comments

Comments
 (0)