53 KiB
Executable File
53 KiB
Executable File
In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import linregressIn [2]:
Snell: pd.DataFrame = pd.DataFrame({
'theta_i':[75, 60, 49, 40, 31, 15],
'dtheta_i':[1.0] * 6,
'theta_t':[40, 35, 30, 25, 20, 10],
'dtheta_t':[0.5] * 6,
'sin_theta_i':[np.nan] * 6,
'sin_theta_t':[np.nan] * 6,
'dsin_theta':[np.nan] * 6
})
Snell['sin_theta_i'] = np.sin(np.radians(Snell['theta_i']))
Snell['sin_theta_t'] = np.sin(np.radians(Snell['theta_t']))
Snell['dsin_theta'] = np.sqrt(
(np.cos(np.radians(Snell['theta_i'])) * np.radians(Snell['dtheta_i']))**2 +
(np.cos(np.radians(Snell['theta_t'])) * np.radians(Snell['dtheta_t']))**2
)
slope, intercept, r_value, p_value, std_err = linregress(Snell['sin_theta_t'], Snell['sin_theta_i'])
plt.errorbar(Snell['sin_theta_t'], Snell['sin_theta_i'], xerr=Snell['dsin_theta'], fmt='o', label='Data with error bars')
plt.plot(Snell['sin_theta_t'], intercept + slope * Snell['sin_theta_t'], 'r', label='Fitted line')
plt.text(0.5, 0.1, f'Slope: {slope:.3f} ± {std_err:.3f}')
plt.xlabel(r'$\sin(\theta_t)$')
plt.ylabel(r'$\sin(\theta_i)$')
plt.title("Snell's Law: Refraction of Light")
plt.legend()
plt.show()
SnellOut [2]:
| theta_i | dtheta_i | theta_t | dtheta_t | sin_theta_i | sin_theta_t | dsin_theta | |
|---|---|---|---|---|---|---|---|
| 0 | 75 | 1.0 | 40 | 0.5 | 0.965926 | 0.642788 | 0.008068 |
| 1 | 60 | 1.0 | 35 | 0.5 | 0.866025 | 0.573576 | 0.011281 |
| 2 | 49 | 1.0 | 30 | 0.5 | 0.754710 | 0.500000 | 0.013720 |
| 3 | 40 | 1.0 | 25 | 0.5 | 0.642788 | 0.422618 | 0.015534 |
| 4 | 31 | 1.0 | 20 | 0.5 | 0.515038 | 0.342020 | 0.017060 |
| 5 | 15 | 1.0 | 10 | 0.5 | 0.258819 | 0.173648 | 0.018923 |
In [3]:
R = lambda L, D, h: ((L - D) ** 2) / (6 * h)
dR = lambda L, D, h, dL, dD, dh: np.sqrt(
((2 * (L - D) / (6 * h)) * dL) ** 2 +
((-2 * (L - D) / (6 * h)) * dD) ** 2 +
(((L - D) ** 2) / (6 * h ** 2) * dh) ** 2
)
f = lambda n, R1, R2: 1 / ((n - 1) * ((1 / R1) - (1 / R2)))
df = lambda n, R1, R2, dn, dR1, dR2: np.sqrt(
(((1 / ((n - 1) ** 2)) * ((1 / R1) - (1 / R2))) * dn) ** 2 +
(((n - 1) / (R1 ** 2)) * dR1) ** 2 +
(((n - 1) / (R2 ** 2)) * dR2) ** 2
)
L = 38
dL = 0.05
D = 6
dD = 0.05
dh = 0.01
n = 1.52
dn = 0.01
h0 = 12.39In [4]:
h11 = 12.82 - h0
h12 = -(12.85 - h0)
R11 = R(L, D, h11)
dR11 = dR(L, D, h11, dL, dD, dh)
R12 = R(L, D, h12)
dR12 = dR(L, D, h12, dL, dD, dh)
print(f"R11: {h11} => {R11} ± {dR11}")
print(f"R12: {h12} => {R12} ± {dR12}")
print(f"Focal length 1: {f(n, R11, R12)} ± {df(n, R11, R12, dn, dR11, dR12)}")R11: 0.4299999999999997 => 396.8992248062018 ± 9.395403049021958 R12: -0.4599999999999991 => -371.0144927536239 ± 8.230511802911352 Focal length 1: 368.76980697205465 ± 0.0001977934990893209
In [5]:
h21 = 15.62 - h0
h22 = -(12.39 - h0)
R21 = R(L, D, h21)
dR21 = dR(L, D, h21, dL, dD, dh)
try:
R22 = R(L, D, h22)
dR22 = dR(L, D, h22, dL, dD, dh)
except ZeroDivisionError:
R22 = np.inf
dR22 = 0
print(f"R21: {h21} => {R21} ± {dR21}")
print(f"R22: {h22} => {R22} ± {dR22}")
print(f"Focal length 2: {f(n, R21, R22)} ± {df(n, R21, R22, dn, dR21, dR22)}")R21: 3.2299999999999986 => 52.837977296181656 ± 0.2851112610049693 R22: -0.0 => inf ± 0 Focal length 2: 101.61149480034932 ± 0.0007019295840153632
In [6]:
f = 250
mh = lambda hi, ho: hi / ho
dmh = lambda hi, ho, dhi, dho: np.sqrt(
(1 / ho * dhi) ** 2 +
(-hi / (ho ** 2) * dho) ** 2
)
ms = lambda si, so: -si / so
dms = lambda si, so, dsi, dso: np.sqrt(
(-1 / so * dsi) ** 2 +
(si / (so ** 2) * dso) ** 2
)
si = lambda so, f: 1 / (1 / f - 1 / so)
dsi = lambda so, f, dso: np.sqrt(
(si(so, f) ** 2 / so ** 2 * dso) ** 2
)
ho = 10
dho = 1In [7]:
so = 350
dso = 1
si_meas = 1225 - so
dsi_meas = 1
si_calc = si(so, f)
dsi_calc = dsi(so, f, dso)
print(f"Measured si: {si_meas} ± {dsi_meas}")
print(f"Calculated si: {si_calc} ± {dsi_calc}")
hi = -26
dhi = 1
m_h = mh(hi, ho)
dm_h = dmh(hi, ho, dhi, dho)
m_s = ms(si_meas, so)
dm_s = dms(si_meas, so, dsi_meas, dso)
print(f"Magnification from heights: {m_h} ± {dm_h}")
print(f"Magnification from distances: {m_s} ± {dm_s}")Measured si: 875 ± 1 Calculated si: 874.9999999999999 ± 6.249999999999998 Magnification from heights: -2.6 ± 0.2785677655436824 Magnification from distances: -2.5 ± 0.00769309258162072
In [8]:
so = 500
dso = 1
si_meas = 1000 - so
dsi_meas = 1
si_calc = si(so, f)
dsi_calc = dsi(so, f, dso)
print(f"Measured si: {si_meas} ± {dsi_meas}")
print(f"Calculated si: {si_calc} ± {dsi_calc}")
hi = -10
dhi = 1
m_h = mh(hi, ho)
dm_h = dmh(hi, ho, dhi, dho)
m_s = ms(si_meas, so)
dm_s = dms(si_meas, so, dsi_meas, dso)
print(f"Magnification from heights: {m_h} ± {dm_h}")
print(f"Magnification from distances: {m_s} ± {dm_s}")Measured si: 500 ± 1 Calculated si: 500.0 ± 1.0 Magnification from heights: -1.0 ± 0.14142135623730953 Magnification from distances: -1.0 ± 0.00282842712474619
In [9]:
so = 650
dso = 1
si_meas = 1057 - so
dsi_meas = 1
si_calc = si(so, f)
dsi_calc = dsi(so, f, dso)
print(f"Measured si: {si_meas} ± {dsi_meas}")
print(f"Calculated si: {si_calc} ± {dsi_calc}")
hi = -0.7
dhi = 1
m_h = mh(hi, ho)
dm_h = dmh(hi, ho, dhi, dho)
m_s = ms(si_meas, so)
dm_s = dms(si_meas, so, dsi_meas, dso)
print(f"Magnification from heights: {m_h} ± {dm_h}")
print(f"Magnification from distances: {m_s} ± {dm_s}")Measured si: 407 ± 1 Calculated si: 406.25 ± 0.390625 Magnification from heights: -0.06999999999999999 ± 0.10024470060806208 Magnification from distances: -0.6261538461538462 ± 0.0018151685914841798
In [10]:
f1 = 75
f2 = 35
f_combined = 1 / (1 / f1 + 1 / f2 - 1 / (f1 + f2))
print(f"Combined focal length of lenses with f1={f1} mm and f2={f2} mm: {f_combined} mm")
ohi = 110
nhi = 160
print(f"hi' / hi = {nhi / ohi}")
Combined focal length of lenses with f1=75 mm and f2=35 mm: 30.474934036939317 mm hi' / hi = 1.4545454545454546
In [11]:
Mmic = lambda fo, fe, so: ((fo) / (fo - so)) * (250 / fe)
dMmic = lambda fo, fe, so, dso: np.sqrt(
((250 / fe) * (fo / (fo - so) ** 2) * dso) ** 2
)
fo = 50
fe = 200
so = 476 - 413
dso = 1
M = Mmic(fo, fe, so)
dM = dMmic(fo, fe, so, dso)
print(f"Magnification of microscope: {M} ± {dM}")Magnification of microscope: -4.8076923076923075 ± 0.3698224852071006
In [12]:
Mtel = lambda fo, fe: - (fo / fe)In [13]:
kfo = 200
kfe = 50
kso = 270 - 40
dkso = 1
Mk = Mtel(kfo, kfe)
print(f"Magnification of Keplerian telescope: {Mk}")
print(f"{kso - (kfo + kfe)}")Magnification of Keplerian telescope: -4.0 -20
In [14]:
gfo = 200
gfe = -50
gso = 195 - 60
dgso = 1
Mg = Mtel(gfo, gfe)
print(f"Magnification of Galilean telescope: {Mg}")
print(f"{gso - (gfo + gfe)}")Magnification of Galilean telescope: 4.0 -15
In [ ]: