Quantum systems and classes

master
E. Almqvist 3 years ago
parent cc12437725
commit 02e3548c6b
  1. 28
      mas/shrodequ_superpos/main.py
  2. 2
      mas/shrodequ_superpos/phys/__init__.py
  3. BIN
      mas/shrodequ_superpos/phys/__pycache__/__init__.cpython-310.pyc
  4. BIN
      mas/shrodequ_superpos/phys/__pycache__/const.cpython-310.pyc
  5. BIN
      mas/shrodequ_superpos/phys/__pycache__/func.cpython-310.pyc
  6. BIN
      mas/shrodequ_superpos/phys/__pycache__/particle.cpython-310.pyc
  7. BIN
      mas/shrodequ_superpos/phys/__pycache__/quantum_systems.cpython-310.pyc
  8. 9
      mas/shrodequ_superpos/phys/box.py
  9. 10
      mas/shrodequ_superpos/phys/const.py
  10. 1
      mas/shrodequ_superpos/phys/func.py
  11. 35
      mas/shrodequ_superpos/phys/particle.py
  12. 21
      mas/shrodequ_superpos/phys/quantum_systems.py

@ -3,19 +3,21 @@ import matplotlib.pyplot as plt
import numpy as np import numpy as np
from phys import * from phys import *
x = np.arange(0, BOX_LENGTH, 0.00001) quantum_system = box(0.001) # box with inf walls
n = np.arange(1, 10, 1)
X, N = np.meshgrid(x, n) # x = np.arange(0, BOX_LENGTH, 0.00001)
P = prob(X, N) # n = np.arange(1, 10, 1)
#
fig = plt.figure() # X, N = np.meshgrid(x, n)
ax = plt.axes(projection='3d') # P = prob(X, N)
ax.plot_surface(X, N, P, rstride=1, cstride=1, cmap='viridis', edgecolor='none') #
ax.set_xlabel('x [m]') # fig = plt.figure()
ax.set_ylabel('n [int]') # ax = plt.axes(projection='3d')
ax.set_zlabel('probability [frac]'); # ax.plot_surface(X, N, P, rstride=1, cstride=1, cmap='viridis', edgecolor='none')
# ax.set_xlabel('x [m]')
plt.show() # ax.set_ylabel('n [int]')
# ax.set_zlabel('probability [frac]');
#
# plt.show()

@ -1,4 +1,4 @@
from phys.func import * from phys.func import *
from phys.const import * from phys.const import *
from phys.box import box from phys.quantum_systems import *
from phys.particle import particle from phys.particle import particle

@ -1,9 +0,0 @@
from phys.particle import particle
class box:
def __init__(self, length: float):
self.length = length
def add_particle(pobj: particle):
pass

@ -13,14 +13,14 @@ def energy(n):
return (((h*n)/BOX_LENGTH)**2)*(1/(8*m)) return (((h*n)/BOX_LENGTH)**2)*(1/(8*m))
# Wave func inner coef # Wave func inner coef
def k(n): def psi_k(n):
return np.sqrt( (8 * ((np.pi)**2) * m * energy(n))/(h**2) ) return np.sqrt( (8 * ((np.pi)**2) * m * energy(n))/(h**2) )
# pre calculate energy states # pre calculate energy states
energy_states = [] energy_def = []
for n in range(0, 11): for n in range(0, 11):
energy_states.append( energy(n) ) energy_def.append( energy(n) )
psi_k = [] psi_k_def = []
for n in range(0, 11): for n in range(0, 11):
psi_k.append( k(n) ) psi_k_def.append( psi_k(n) )

@ -1,4 +1,3 @@
import cmath
import numpy as np import numpy as np
from phys.const import * from phys.const import *

@ -1,11 +1,36 @@
from phys.func import psi, prob, E from phys.func import psi, prob
from phys.const import energy, psi_k
from phys.quantum_systems import *
import numpy as np
import cmath
from scipy.constants import Planck
class particle: class particle:
def __init__(self, mass: float, n_state: int): def __init__(self, mass: float, system: infbox, n_state: int=1):
self.mass = mass if n_state < 1:
self.n_state = n_state print(f"Particle energy state index must be 1 or more! {n_state=}")
return
self.mass = mass # particle mass
self.n_state = n_state # energy state index
self.system = system # quantum system
self.energy = self.energy = energy(self.n_state) # total energy "for" the particle
self.psi_k = psi_k(self.n_state) # wave function coeff-
self.system.add_particle(self)
def psi(self, x: float):
return self.system.norm_factor * np.sin(self.psi_k * x)
def wave(self, x: float, time: float) -> complex:
z_coef = -( (2*np.pi*self.energy*time)/Planck ) # exponent coef
z = complex(0, z_coef) # full coef (complex)
time_factor = cmath.exp(z) # TODO: cmath.exp is weird, verify...
psi = self.system.norm_factor * np.sin(self.psi_k * x)
return psi * time_factor

@ -0,0 +1,21 @@
from phys.particle import particle
import numpy as np
class quantum_system:
def __init__(self, name: str):
self.name = name
self.particles = []
def add_particle(particle: particle):
self.particles.append(particle)
print(f"Added particle {particle} to quantum system '{self.name}'")
class infbox(quantum_system):
def __init__(self, length: float):
super
self.name = "Inf Box"
self.length = length
self.norm_factor = np.sqrt(2/self.length)
Loading…
Cancel
Save