Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- from mpl_toolkits.mplot3d import Axes3D
- from matplotlib.animation import FuncAnimation
- from matplotlib.widgets import Slider
- # Define the 3D wavefunction in spherical coordinates
- def wavefunction(theta, phi, r, k_theta, k_phi, k_r, omega, t):
- return np.exp(1j * (k_theta * theta + k_phi * phi + k_r * r - omega * t))
- # Define parameters
- k_theta, k_phi, k_r = 1.0, 1.0, 1.0
- omega = 1.0
- # Create the figure and slider axes
- fig = plt.figure(figsize=(12, 10))
- ax = fig.add_subplot(111, projection='3d')
- slider_ax = plt.axes([0.2, 0.02, 0.6, 0.03]) # Slider position (left, bottom, width, height)
- # Initialize the slider for controlling the number of displayed data points
- num_points_slider = Slider(slider_ax, 'Points', valmin=10, valmax=30, valinit=30, valstep=1)
- # Animation update function
- def update(frame):
- ax.clear()
- # Adjust the number of points based on slider value
- num_points = int(num_points_slider.val)
- theta = np.linspace(0, 2 * np.pi, num_points)
- phi = np.linspace(0, 2 * np.pi, num_points)
- r = np.linspace(0.5, 5.0, num_points)
- Theta, Phi, R = np.meshgrid(theta, phi, r)
- # Convert to Cartesian coordinates for visualization
- X = R * np.cos(Phi) * np.sin(Theta)
- Y = R * np.sin(Phi) * np.sin(Theta)
- Z = R * np.cos(Theta)
- # Compute the wavefunction and density matrix
- t = frame / 20000.0 # Speed increased by a factor of 20,000x
- Psi = wavefunction(Theta, Phi, R, k_theta, k_phi, k_r, omega, t)
- rho = np.abs(Psi)**2 # Density matrix (real values)
- # Compute entropy (S) and bio-enthalpy (H_B)
- S = -rho * np.log(rho + 1e-9) # Adding a small term to avoid log(0)
- H_B = rho + np.abs(np.gradient(Psi.real)[0])**2 + np.abs(np.gradient(Psi.real)[1])**2 + np.abs(np.gradient(Psi.real)[2])**2
- # Normalize S and H_B for visualization purposes
- S_normalized = S / np.max(S)
- H_B_normalized = H_B / np.max(H_B)
- # Plot entropy and bio-enthalpy together using color mapping
- scatter_entropy = ax.scatter(
- X.flatten(), Y.flatten(), Z.flatten(),
- c=S_normalized.flatten(), cmap='twilight', alpha=0.6,
- label="Entropy"
- )
- scatter_enthalpy = ax.scatter(
- X.flatten(), Y.flatten(), Z.flatten(),
- c=H_B_normalized.flatten(), cmap='hsv', alpha=0.4,
- label="Bio-Enthalpy"
- )
- # # Add vector arrows (gradient of Psi) - COMMENTED OUT
- # # ax.quiver(
- # # X[::3].flatten(), Y[::3].flatten(), Z[::3].flatten(),
- # # grad_Psi_x[::3].flatten(), grad_Psi_y[::3].flatten(), grad_Psi_z[::3].flatten(),
- # # length=0.5, normalize=True,
- # # color="blue", alpha=0.7,
- # # label="Gradient Arrows"
- # # )
- # Add titles and labels
- ax.set_title(f'Entropy vs Bio-Enthalpy at t={t:.6f}')
- ax.set_xlabel('X')
- ax.set_ylabel('Y')
- ax.set_zlabel('Z')
- # Load and animate the first 10 seconds with increased speed
- def load_and_animate(duration=10, fps=30):
- frames = int(fps * duration) # Total number of frames
- ani = FuncAnimation(fig, update, frames=frames, interval=1000 / fps) # Interval in milliseconds
- plt.show()
- # Connect slider interaction to update function
- def slider_update(val):
- update(0) # Update with initial time t=0 to reflect new slider value
- num_points_slider.on_changed(slider_update)
- # Run animation with interactive controls
- load_and_animate(duration=10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement