Sunday, 6 April 2025

Gravitational Wave Simulation Pattern using Python

 


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 numpy as np

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

NumPy (np): Used for numerical computations and generating grid points.

 Matplotlib (plt): Used for plotting the 3D gravitational wave surface.

 mpl_toolkits.mplot3d: Enables 3D plotting.

 

2. 2Define the Grid for the Simulation

 x = np.linspace(-5, 5, 100)  # X-axis range (-5 to 5) with 100 points

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.

 np.meshgrid(x, y): Generates a grid of (X, Y) coordinates, forming a 2D plane where the wave will be calculated.

 

3.Define Gravitational Wave Parameters

 frequency = 3  # Number of oscillations per unit distance

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.

 wavelength: Represents the distance between peaks (not directly used in this equation).

 amplitude: Defines the height of the wave (maximum space-time distortion).

 time = 0: For a static snapshot; can be animated to show real-time wave evolution.

 

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)):

 r = (X² + Y²)^(0.5): Represents the radial distance from the center (like ripples on water).

 sin(frequency * r - time): Creates oscillations (wave-like structure).

 Damping Component (exp(-0.2 * r^2)):

 The exponential decay ensures that waves fade as they move outward.

 Models how gravitational waves weaken over long distances (like real astrophysical waves).

 Multiplication with amplitude: Scales the wave intensity.

 

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.

 ax = fig.add_subplot(111, projection="3d"): Creates a 3D plot using Matplotlib.

 

6.Plot the Gravitational Wave Surface

 ax.plot_surface(X, Y, Z, cmap="coolwarm", edgecolor="none")

plot_surface(X, Y, Z): Creates a 3D surface plot from the computed values.

 cmap="coolwarm": Uses a blue-red colormap to highlight the wave crests and troughs.

 edgecolor="none": Removes edge lines for a smooth visualization.

 

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.

 Title describes the astrophysical concept being visualized.

 

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.

 
9. Display the Final 3D Plot

 plt.show()

Displays the gravitational wave simulation.


Related Posts:

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (98) AI (40) Android (24) AngularJS (1) Api (2) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (198) C (77) C# (12) C++ (83) Course (67) Coursera (251) Cybersecurity (25) Data Analysis (3) Data Analytics (3) data management (11) Data Science (149) Data Strucures (8) Deep Learning (21) Django (16) Downloads (3) edx (2) Engineering (14) Euron (29) Events (6) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Generative AI (11) Google (36) Hadoop (3) HTML Quiz (1) HTML&CSS (47) IBM (30) IoT (1) IS (25) Java (93) Java quiz (1) Leet Code (4) Machine Learning (85) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (4) Pandas (4) PHP (20) Projects (29) pyth (1) Python (1055) Python Coding Challenge (461) Python Quiz (128) Python Tips (5) Questions (2) R (70) React (6) Scripting (3) security (3) Selenium Webdriver (4) Software (17) SQL (42) UX Research (1) web application (8) Web development (4) web scraping (2)

Followers

Python Coding for Kids ( Free Demo for Everyone)