| | 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) |
| |
|
| | |
| | Q = 2 ** (1/12) |
| |
|
| | |
| | def wave_function_cupy(x, t, scale=1.0, phase_shift=0.0): |
| | denominator = 2 * (t**2 + 1e-10) |
| | return scale * Q * cp.exp(-x**2 / denominator) * cp.exp(-1j * (t + phase_shift)) |
| |
|
| | |
| | x = np.linspace(-10, 10, 100) |
| | t = np.linspace(0, 10, 100) |
| | X, T = np.meshgrid(x, t) |
| |
|
| | |
| | X_cupy = cp.asarray(X) |
| | T_cupy = cp.asarray(T) |
| |
|
| | |
| | scales = [0.5, 1.0, 1.5] |
| | phase_shifts = [0, np.pi/4, np.pi/2] |
| |
|
| | |
| | wave_functions_3d = np.zeros((len(scales), len(phase_shifts), len(x), len(t)), dtype=complex) |
| |
|
| | |
| | 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)) |
| |
|
| | |
| |
|
| | |
| | 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" |
| | ), |
| | ) |
| |
|
| | |
| | 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]} |
| | ], |
| | label=f"Scale: {scales[i]:.2f}" |
| | ) for i in range(len(scales)) |
| | ], |
| | pad=dict(t=50), |
| | len=0.9, |
| | x=0.1, |
| | y=0.1, |
| | ), |
| | 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]} |
| | ], |
| | label=f"Phase Shift: {phase_shifts[j]:.2f}" |
| | ) for j in range(len(phase_shifts)) |
| | ], |
| | pad=dict(t=50), |
| | len=0.9, |
| | x=0.1, |
| | y=0.3, |
| | ) |
| | ] |
| | ) |
| |
|
| | fig.show() |
| |
|
| | |
| |
|
| | |
| |
|
| | |
| | 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)) |
| | im.set_array(np.abs(wave_functions_3d[i, j, :, :]) ** 2) |
| | 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() |
| |
|