Add problems
This commit is contained in:
parent
b5b593f061
commit
51b0c79ca3
@ -1,5 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.11 (quantum-dev)" />
|
||||||
|
</component>
|
||||||
<component name="MarkdownSettingsMigration">
|
<component name="MarkdownSettingsMigration">
|
||||||
<option name="stateVersion" value="1" />
|
<option name="stateVersion" value="1" />
|
||||||
</component>
|
</component>
|
||||||
|
24
ps9-1a.py
Normal file
24
ps9-1a.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import numpy as np
|
||||||
|
import pylab as pl
|
||||||
|
|
||||||
|
a = 1
|
||||||
|
n_vals = [n for n in range(1, 7)]
|
||||||
|
|
||||||
|
x_vals = np.linspace(-a / 2, a / 2, 1000)
|
||||||
|
|
||||||
|
psi_evens = []
|
||||||
|
psi_odds = []
|
||||||
|
for n in n_vals:
|
||||||
|
if n % 2 == 0:
|
||||||
|
psi_evens.append(np.sqrt(2 / a) * np.sin(n * np.pi * x_vals / a))
|
||||||
|
else:
|
||||||
|
psi_odds.append(np.sqrt(2 / a) * np.cos(n * np.pi * x_vals / a))
|
||||||
|
|
||||||
|
pl.title("First 6 Solutions for Infinite Square Well")
|
||||||
|
for psi_even in psi_evens:
|
||||||
|
pl.plot(x_vals, psi_even, color='blue')
|
||||||
|
for psi_odd in psi_odds:
|
||||||
|
pl.plot(x_vals, psi_odd, color='green')
|
||||||
|
pl.vlines([-a / 2, a / 2], ymin=-2, ymax=2, color='red')
|
||||||
|
pl.grid()
|
||||||
|
pl.show()
|
19
ps9-1b.py
Normal file
19
ps9-1b.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
a = 1
|
||||||
|
n_vals = [n for n in range(1, 7)]
|
||||||
|
|
||||||
|
N = 1000
|
||||||
|
dx = 1 / N
|
||||||
|
x_vals = np.linspace(-a / 2, a / 2, N)
|
||||||
|
|
||||||
|
psi_evens = []
|
||||||
|
psi_odds = []
|
||||||
|
for n in n_vals:
|
||||||
|
if n % 2 == 0:
|
||||||
|
psi_evens.append(np.sqrt(2 / a) * np.sin(n * np.pi * x_vals / a))
|
||||||
|
else:
|
||||||
|
psi_odds.append(np.sqrt(2 / a) * np.cos(n * np.pi * x_vals / a))
|
||||||
|
|
||||||
|
for i in range(min(len(psi_evens), len(psi_odds))):
|
||||||
|
print(f'psi_even_{i + 1} * psi_odd_{i + 1} = {np.dot(psi_evens[i], psi_odds[i]) * dx}')
|
44
ps9-2.py
Normal file
44
ps9-2.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
a = 1
|
||||||
|
hbar = 1.054572e-34
|
||||||
|
n_vals = [n for n in range(1, 7)]
|
||||||
|
|
||||||
|
N = 1000
|
||||||
|
dx = 1 / N
|
||||||
|
x_vals = np.linspace(-a / 2, a / 2, N)
|
||||||
|
|
||||||
|
psi_funcs = []
|
||||||
|
psi_derivs = []
|
||||||
|
psi_2nd_derivs = []
|
||||||
|
for n in n_vals:
|
||||||
|
if n % 2 == 0:
|
||||||
|
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)))
|
||||||
|
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)))
|
||||||
|
|
||||||
|
print("======= expect_x =======")
|
||||||
|
for i in range(len(psi_funcs)):
|
||||||
|
expect_x = np.sum(psi_funcs[i] ** 2 * x_vals) * dx
|
||||||
|
print(f'expect_x_{i + 1} = {expect_x}')
|
||||||
|
|
||||||
|
print("======= expect_x^2 =======")
|
||||||
|
for i in range(len(psi_funcs)):
|
||||||
|
expect_x_sqrd = np.sum(psi_funcs[i] ** 2 * x_vals ** 2) * dx
|
||||||
|
print(f'expect_x^2_{i + 1} = {expect_x_sqrd}')
|
||||||
|
|
||||||
|
print("======= expect_p =======")
|
||||||
|
for i in range(len(psi_funcs)):
|
||||||
|
expect_p = np.sum(psi_funcs[i] * 1j * hbar * psi_derivs[i]) * dx
|
||||||
|
print(f'expect_p_{i + 1} = {expect_p}')
|
||||||
|
|
||||||
|
print("======= expect_p^2 =======")
|
||||||
|
for i in range(len(psi_funcs)):
|
||||||
|
expect_p_sqrd = np.sum(psi_funcs[i] * hbar ** 2 * psi_2nd_derivs[i]) * dx
|
||||||
|
print(f'expect_p^2_{i + 1} = {expect_p_sqrd}')
|
Loading…
Reference in New Issue
Block a user