File size: 3,946 Bytes
a0589da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
125
126
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import cupy as cp
from tqdm import tqdm
import plotly.graph_objects as go
import streamlit as st

x = st.slider('Select a value')
st.write(x, 'squared is', x * x)

# Define the twelfth root of two
Q = 2 ** (1/12)

# Define the wave function of the universe with variants (using CuPy)
def wave_function_cupy(x, t, scale=1.0, phase_shift=0.0):
    denominator = 2 * (t**2 + 1e-10)  # Add a small value to avoid division by zero
    return scale * Q * cp.exp(-x**2 / denominator) * cp.exp(-1j * (t + phase_shift))

# Simulation parameters
x = np.linspace(-10, 10, 100)
t = np.linspace(0, 10, 100)
X, T = np.meshgrid(x, t)

# Convert numpy arrays to CuPy arrays
X_cupy = cp.asarray(X)
T_cupy = cp.asarray(T)

# Variants parameters
scales = [0.5, 1.0, 1.5]  # Different scaling factors
phase_shifts = [0, np.pi/4, np.pi/2]  # Different phase shifts

# Initialize a 3D array to store results
wave_functions_3d = np.zeros((len(scales), len(phase_shifts), len(x), len(t)), dtype=complex)

# Simulate with variants and store results in the 3D array
for i, scale in enumerate(scales):
    for j, phase_shift in enumerate(phase_shifts):
        wave_functions_3d[i, j, :, :] = cp.asnumpy(wave_function_cupy(X_cupy, T_cupy, scale, phase_shift))

# --- Plotly Interactive Visualization ---

# Create the figure
fig = go.Figure(data=[
    go.Surface(x=x, y=t, z=np.abs(wave_functions_3d[0, 0, :, :])**2)
])

fig.update_layout(
    title="Wave Function of the Universe",
    scene=dict(
        xaxis_title="x",
        yaxis_title="t",
        zaxis_title="|ψ(x,t)|^2"
    ),
)

# Add Scale Slider
fig.update_layout(
    sliders=[
        dict(
            active=True,
            currentvalue=dict(
                prefix="Scale: ",
                font=dict(size=12)
            ),
            steps=[
                dict(
                    method="update",
                    args=[
                        {"z": [np.abs(wave_functions_3d[i, 0, :, :])**2]}  # Update z data
                    ],
                    label=f"Scale: {scales[i]:.2f}"  # Label for step values
                ) for i in range(len(scales))
            ],
            pad=dict(t=50),
            len=0.9,  # Length of the slider
            x=0.1,    # X position of the slider
            y=0.1,    # Y position of the slider
        ),
        dict(
            active=True,
            currentvalue=dict(
                prefix="Phase Shift: ",
                font=dict(size=12)
            ),
            steps=[
                dict(
                    method="update",
                    args=[
                        {"z": [np.abs(wave_functions_3d[0, j, :, :])**2]}  # Update z data
                    ],
                    label=f"Phase Shift: {phase_shifts[j]:.2f}"  # Label for step values
                ) for j in range(len(phase_shifts))
            ],
            pad=dict(t=50),
            len=0.9,  # Length of the slider
            x=0.1,    # X position of the slider
            y=0.3,    # Y position of the slider
        )
    ]
)

fig.show()

# --- End of Plotly ---

# --- Matplotlib Animation ---

# Animation
fig, ax = plt.subplots()
im = ax.imshow(np.abs(wave_functions_3d[0, 0, :, :]) ** 2, extent=[-10, 10, 0, 10], aspect='auto', cmap='viridis')
ax.set_xlabel('x')
ax.set_ylabel('t')
ax.set_title('Wave Function of the Universe')
cbar = fig.colorbar(im, ax=ax, label='|ψ(x,t)|^2')

def update(frame):
    i, j = divmod(frame, len(phase_shifts))  # Get the index for the 3D array
    im.set_array(np.abs(wave_functions_3d[i, j, :, :]) ** 2)  # Update with the correct frame
    ax.set_title(f'Wave Function at Scale: {scales[i]}, Phase Shift: {phase_shifts[j]:.2f}')
    return im,

ani = FuncAnimation(fig, update, frames=len(scales) * len(phase_shifts), blit=True)
ani.save('wave_function_animation.gif', writer='pillow')
plt.show()