-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproof_postulate.py
124 lines (98 loc) · 3.82 KB
/
proof_postulate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from typing import Any
import matplotlib.pyplot as plt
import numpy as np
from fibonacci_simulation_refactored import (
generate_fibonacci_sequence,
normalize_fibonacci_sequence,
initialize_wave_function,
evolve_wave_function
)
# Define constants
hbar = 1.0 # Reduced Planck's constant (in natural units for simplicity)
m = 1.0 # Mass of the particle (also in natural units)
L = 10.0 # Length of the domain
N = 100 # Number of grid points
dx = L / N # Spatial step size
dt = 0.01 # Time step
# Define spatial grid points
x = np.linspace(0, L, N)
# Define potentials
v_constant = np.ones_like(x) * 0.5 # Uniform constant potential
v_quadratic = 0.1 * (x - L / 2) ** 2 # Quadratic potential
# Generate Fibonacci sequence and normalize it
fib_sequence = generate_fibonacci_sequence(N)
fib_ratios = normalize_fibonacci_sequence(fib_sequence, L)
v_fibonacci = fib_ratios
# Debugging: Validate potentials
print("Fibonacci Ratios:", fib_ratios)
print("v_fibonacci shape:", v_fibonacci.shape)
print("v_constant shape:", v_constant.shape)
print("v_quadratic shape:", v_quadratic.shape)
# Check grid consistency
assert len(x) == len(v_fibonacci), "Mismatch between spatial grid and Fibonacci potential"
# Initialize wave function
center = L / 2
width = 1.0
psi_global = initialize_wave_function(x, center, width)
# Generate Fibonacci sequence and normalize it
fib_sequence = generate_fibonacci_sequence(N)
fib_ratios = normalize_fibonacci_sequence(fib_sequence, L)
# Define potentials
v_fibonacci = fib_ratios # Fibonacci potential
v_constant = np.ones_like(x) * 0.5 # Uniform constant potential
v_quadratic = 0.1 * (x - L / 2) ** 2 # Quadratic potential
# Debugging: Validate potentials
print("Fibonacci Ratios:", fib_ratios)
print("v_fibonacci shape:", v_fibonacci.shape)
print("v_constant shape:", v_constant.shape)
print("v_quadratic shape:", v_quadratic.shape)
# Check grid consistency
assert len(x) == len(v_fibonacci), "Mismatch between spatial grid and Fibonacci potential"
# Initialize wave function
center = L / 2
width = 1.0
psi_global = initialize_wave_function(x, center, width)
# Helper Functions
def track_variance(psi, potential, dx, time_steps):
"""Track variance for the given potential."""
var_list = []
psi_current = psi.copy()
for _ in range(time_steps):
psi_current = evolve_wave_function(psi_current, potential, dx, dt)
com = np.sum(x * np.abs(psi_current)**2) * dx
var = np.sum((x - com)**2 * np.abs(psi_current)**2) * dx
var_list.append(var)
return var_list
def compute_energies(psi_current, v_fibonacci, dx, hbar, m):
"""
Compute kinetic and potential energy from a given wavefunction and potential.
Parameters:
psi_current (np.ndarray): Current wavefunction values (complex array).
v_fibonacci (np.ndarray): Potential function values.
dx (float): Spatial step size.
hbar (float): Reduced Planck's constant.
m (float): Mass of the particle.
Returns:
float: Kinetic energy.
float: Potential energy.
"""
# Compute the magnitude of the wavefunction
magnitude = np.abs(psi_current)
grad_magnitude = np.gradient(magnitude, dx)
# Compute the kinetic energy
squared_gradient = grad_magnitude ** 2
kinetic_energy = 0.5 * hbar ** 2 / m * np.sum(squared_gradient) * dx
# Compute the potential energy
potential_energy = np.sum(v_fibonacci * magnitude ** 2) * dx
# Return the computed energies
return kinetic_energy, potential_energy
def plot_variance(time_steps, dt, var_lists, labels, title):
"""Plot variance comparison."""
plt.figure(figsize=(12, 6))
for var_list, label in zip(var_lists, labels):
plt.plot(np.arange(time_steps) * dt, var_list, label=label)
plt.xlabel('Time')
plt.ylabel('Variance')
plt.title(title)
plt.legend()
plt.show()