I used import matplotlib.pyplot as plt
import numpy as np
# Constants
G = 6.67430e-11 # Gravitational constant (m^3 kg^-1 s^-2)
M = 1.989e30 # Mass of the black hole (kg), e.g., mass of the Sun
dt = 1e3 # Time step (seconds)
num_steps = 1000 # Number of steps in the simulation
# Initial conditions
position = np.array([1e11, 0]) # Initial position (m)
velocity = np.array([0, 1e4]) # Initial velocity (m/s)
# Lists to store the trajectory
positions = []
# Simulation loop
for _ in range(num_steps):
r = np.linalg.norm(position) # Distance from the black hole
force_magnitude = G * M / r**2
force_direction = -position / r
force = force_magnitude * force_direction
# Update velocity and position
velocity += force * dt
position += velocity * dt
# Store position
positions.append(position.copy())
# Convert to numpy array for easy plotting
positions = np.array(positions)
# Plotting the trajectory
plt.figure(figsize=(8, 8))
plt.pl