Finish ps9-2
This commit is contained in:
parent
51b0c79ca3
commit
24168add3c
36
ps9-2.py
36
ps9-2.py
@ -16,29 +16,57 @@ for n in n_vals:
|
||||
psi_funcs.append(np.sqrt(2 / a) * np.sin(n * np.pi * x_vals / a))
|
||||
psi_derivs.append(np.sqrt(2) * np.pi * n * np.cos(np.pi * n * x_vals / a) / (a * np.sqrt(a)))
|
||||
psi_2nd_derivs.append(
|
||||
-(np.sqrt(2) * np.pi ** 2 * n ** 2 * np.sin(np.pi * n * x_vals / a)) / (a ** 2 * np.sqrt(a)))
|
||||
(np.sqrt(2) * np.pi ** 2 * n ** 2 * np.sin(np.pi * n * x_vals / a)) / (a ** 2 * np.sqrt(a)))
|
||||
else:
|
||||
psi_funcs.append(np.sqrt(2 / a) * np.cos(n * np.pi * x_vals / a))
|
||||
psi_derivs.append(-(np.sqrt(2) * np.pi * n * np.sin(np.pi * n * x_vals / a)) / (a * np.sqrt(a)))
|
||||
psi_2nd_derivs.append(
|
||||
-(np.sqrt(2) * np.pi ** 2 * n ** 2 * np.cos(np.pi * n * x_vals / a)) / (a ** 2 * np.sqrt(a)))
|
||||
(np.sqrt(2) * np.pi ** 2 * n ** 2 * np.cos(np.pi * n * x_vals / a)) / (a ** 2 * np.sqrt(a)))
|
||||
|
||||
print("======= expect_x =======")
|
||||
expect_x_vals = []
|
||||
for i in range(len(psi_funcs)):
|
||||
expect_x = np.sum(psi_funcs[i] ** 2 * x_vals) * dx
|
||||
expect_x = np.sum(psi_funcs[i] * x_vals * psi_funcs[i]) * dx
|
||||
expect_x_vals.append(expect_x)
|
||||
print(f'expect_x_{i + 1} = {expect_x}')
|
||||
|
||||
print("======= expect_x^2 =======")
|
||||
expect_x_sqrd_vals = []
|
||||
for i in range(len(psi_funcs)):
|
||||
expect_x_sqrd = np.sum(psi_funcs[i] ** 2 * x_vals ** 2) * dx
|
||||
expect_x_sqrd = np.sum(psi_funcs[i] * x_vals ** 2 * psi_funcs[i]) * dx
|
||||
expect_x_sqrd_vals.append(expect_x_sqrd)
|
||||
print(f'expect_x^2_{i + 1} = {expect_x_sqrd}')
|
||||
|
||||
print("======= expect_p =======")
|
||||
expect_p_vals = []
|
||||
for i in range(len(psi_funcs)):
|
||||
expect_p = np.sum(psi_funcs[i] * 1j * hbar * psi_derivs[i]) * dx
|
||||
expect_p_vals.append(expect_p)
|
||||
print(f'expect_p_{i + 1} = {expect_p}')
|
||||
|
||||
print("======= expect_p^2 =======")
|
||||
expect_p_sqrd_vals = []
|
||||
for i in range(len(psi_funcs)):
|
||||
expect_p_sqrd = np.sum(psi_funcs[i] * hbar ** 2 * psi_2nd_derivs[i]) * dx
|
||||
expect_p_sqrd_vals.append(expect_p_sqrd)
|
||||
print(f'expect_p^2_{i + 1} = {expect_p_sqrd}')
|
||||
|
||||
print("======= sigma_x =======")
|
||||
sigma_x_vals = []
|
||||
for i in range(len(psi_funcs)):
|
||||
sigma_x = np.sqrt(expect_x_sqrd_vals[i] - expect_x_vals[i] ** 2)
|
||||
sigma_x_vals.append(sigma_x)
|
||||
print(f'sigma_x_{i + 1} = {sigma_x}')
|
||||
|
||||
print("======= sigma_p =======")
|
||||
sigma_p_vals = []
|
||||
for i in range(len(psi_funcs)):
|
||||
sigma_p = np.real(np.sqrt(expect_p_sqrd_vals[i] - expect_p_vals[i] ** 2))
|
||||
sigma_p_vals.append(sigma_p)
|
||||
print(f'sigma_p_{i + 1} = {sigma_p}')
|
||||
|
||||
print("======= uncertainty =======")
|
||||
print(f'hbar/2 = {hbar / 2}')
|
||||
for i in range(len(psi_funcs)):
|
||||
uncertainty = sigma_x_vals[i] * sigma_p_vals[i]
|
||||
print(f'sigma_x_{i + 1}*sigma_p_{i + 1} = {uncertainty}')
|
||||
|
Loading…
Reference in New Issue
Block a user