import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
x = np.linspace(-5, 5, 100)
y = np.linspace(-5, 5, 100)
X, Y = np.meshgrid(x, y)
frequency=3
wavelength=2
amplitude=1
time=0
Z = amplitude * np.sin(frequency * (X**2 + Y**2)**0.5 - time) * np.exp(-0.2 * (X**2 + Y**2))
fig=plt.figure(figsize=(10,7))
ax=fig.add_subplot(111,projection="3d")
ax.plot_surface(X,Y,Z,cmap="coolwarm",edgecolor="none")
ax.set_xlabel("X Axis")
ax.set_ylabel("Y Axis")
ax.set_zlabel("Space Time Curvature")
ax.set_title("Gravitation tides Wave simulation")
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])
plt.show()
#source code --> clcoding.com
Code Explanation:
1.
Import Required Libraries
import
matplotlib.pyplot as plt
from
mpl_toolkits.mplot3d import Axes3D
NumPy (np): Used
for numerical computations and generating grid points.
2.
2Define the Grid for the Simulation
y = np.linspace(-5,
5, 100) # Y-axis range (-5 to 5) with
100 points
X, Y =
np.meshgrid(x, y) # Create a 2D mesh
grid from x and y values
np.linspace(-5, 5,
100): Creates 100 evenly spaced points in the range [-5, 5] for x and y axes.
3.Define
Gravitational Wave Parameters
wavelength = 2 # Distance between peaks (not directly used
here)
amplitude = 1 # Maximum wave height
time = 0 # Static snapshot (can animate later)
frequency: Controls
how many oscillations (wave peaks) occur in the simulation.
4.
Compute the 3D Gravitational Wave Surface
Z = amplitude *
np.sin(frequency * (X**2 + Y**2)**0.5 - time) * np.exp(-0.2 * (X**2 + Y**2))
This equation
models the gravitational wave pattern:
Wave Component
(sin(f * r - t)):
5.Create
the 3D Figure and Axes
fig =
plt.figure(figsize=(10, 7))
ax =
fig.add_subplot(111, projection="3d")
figsize=(10,7):
Sets the figure size for a better view.
6.Plot
the Gravitational Wave Surface
plot_surface(X, Y,
Z): Creates a 3D surface plot from the computed values.
7. Add
Labels and Title
ax.set_xlabel("X
Axis")
ax.set_ylabel("Y
Axis")
ax.set_zlabel("Space-Time
Curvature")
ax.set_title("
Gravitational Tides – 3D Gravitational Wave Simulation")
Labels each axis to
indicate spatial directions and wave intensity.
8.Remove
Grid Ticks for a Clean Look
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])
Removes axis ticks
to make the plot clean and visually appealing.
Displays the
gravitational wave simulation.
0 Comments:
Post a Comment