Fix ps16-1

This commit is contained in:
orosmatthew 2024-04-09 12:36:04 -04:00
parent 38ddca0596
commit fff1d92191
2 changed files with 36 additions and 1 deletions

View File

@ -5,7 +5,7 @@ a = 10
D = 1 D = 1
hbar = 1 hbar = 1
m = 1 m = 1
zs = np.array([5.963, 2.851, 1.745, 1.124]) zs = np.array([2.991, 5.98, 8.96, 11.927])
l = zs / a l = zs / a
V0 = 2 V0 = 2
@ -41,4 +41,5 @@ pl.rcParams['figure.dpi'] = 300
pl.plot(x, V0_graph) pl.plot(x, V0_graph)
for (i, psi) in enumerate(psis): for (i, psi) in enumerate(psis):
pl.plot(x, psi, label=f'psi_odd_{i} z={zs[i]}') pl.plot(x, psi, label=f'psi_odd_{i} z={zs[i]}')
pl.legend()
pl.show() pl.show()

34
ps16-3.py Normal file
View File

@ -0,0 +1,34 @@
from typing import Callable
import numpy as np
z0 = 20
def find_root(f: Callable[[float], float], left: float, right: float, tolerance: float = 1e-6,
max_iter: int = 100) -> float | None:
a = f(left)
b = f(right)
x = None
for _ in range(max_iter):
if abs(a - b) < tolerance:
break
x = left - a * (left - right) / (a - b)
y = f(x)
if abs(y) < tolerance:
break
right, b = left, a
left, a = x, y
return x
def cot(x):
return 1 / np.tan(x)
def func(z: float) -> float:
first = np.sqrt((z0 / z) ** 2 - 1)
second = cot(z)
return first - second
print(find_root(func, 6.2, 6.4, max_iter=1000))