Modern Phys Lab Planck's Constant Update

This commit is contained in:
Nathan Nguyen
2025-02-09 14:32:41 -06:00
parent 42fa7564e9
commit c4e52e6b0e
2 changed files with 24 additions and 14 deletions

View File

@@ -5,11 +5,11 @@ import scipy
colors = ['blue', 'green', 'orange', 'purple', 'red'] colors = ['blue', 'green', 'orange', 'purple', 'red']
wavelengths = { wavelengths = {
'blue': 465, 'blue': 465 * 10**(-9),
'green': 520, 'green': 520 * 10**(-9),
'orange': 589, 'orange': 589 * 10**(-9),
'purple': 390, 'purple': 390 * 10**(-9),
'red': 622 'red': 622 * 10**(-9)
} }
u_0 = np.empty((len(colors))) u_0 = np.empty((len(colors)))
@@ -28,7 +28,7 @@ for color_index, color in enumerate(colors):
for index, line in enumerate(lines): for index, line in enumerate(lines):
parts = line.split('\t') parts = line.split('\t')
voltage[index] = float(parts[0]) voltage[index] = float(parts[0])
current[index] = float(parts[1]) current[index] = float(parts[1]) / 1000
## Line 1 ## Line 1
line_1_bound = len(lines) // 3 line_1_bound = len(lines) // 3
@@ -53,18 +53,28 @@ for color_index, color in enumerate(colors):
ax.legend() ax.legend()
ax.set_title(f"Voltage v Current ({color})") ax.set_title(f"Voltage v Current ({color})")
ax.set_xlabel("Voltage (V)") ax.set_xlabel("Voltage (V)")
ax.set_ylabel("Current (mA)") ax.set_ylabel("Current (A)")
u_0[color_index] = intersect_y[0] u_0[color_index] = intersect_x[0]
wavelength_inv[color_index] = 1 / wavelengths[color] wavelength_inv[color_index] = 1 / wavelengths[color]
plt.show() plt.show()
line = polynomial.Polynomial.fit(u_0, wavelength_inv, 1) line = polynomial.Polynomial.fit(wavelength_inv, u_0, 1).convert()
space = np.linspace(min(u_0), max(u_0)) line = line.convert(domain = [min(wavelength_inv), max(wavelength_inv)]).convert()
plt.plot(space, line(space), color='orange', label='Trendline 2')
plt.scatter(u_0, wavelength_inv) s_2 = (1 / (len(wavelength_inv) - 2)) * sum((u_0 - line.coef[1] * wavelength_inv - line.coef[0]) ** 2)
plt.xlabel("U_0") delta_p = len(wavelength_inv) * sum(wavelength_inv ** 2) - (sum(wavelength_inv) ** 2)
plt.ylabel("1/Wavelength") slope_error = np.sqrt(len(wavelength_inv) / delta_p) * np.sqrt(s_2)
print(delta_p)
print(slope_error)
print(s_2)
space = np.linspace(min(wavelength_inv), max(wavelength_inv))
plt.plot(space, line(space), color='orange', label=f'{line.convert()}')
plt.scatter(wavelength_inv,u_0)
plt.ylabel("U_0")
plt.xlabel("1/Wavelength")
plt.legend()
plt.show() plt.show()