import numpy as np

import matplotlib.pyplot as plt

# Constants
G = 1
M = 1
a = 1

# Radial coordinate
r = np.linspace(0, 2, 500)

# Potential inside the sphere (r <= a)
def potential_inside(r):
    return -G * M * (3 * a**2 - r**2) / (2 * a**3)

# Potential outside the sphere (r > a)
def potential_outside(r):
    return -G * M / r

# Calculate potentials
potential_in = potential_inside(r[r <= a])
potential_out = potential_outside(r[r > a])

# Plotting
plt.figure(figsize=(10, 6))
plt.plot(r[r <= a], potential_in, label='Внутренний потенциал')
plt.plot(r[r > a], potential_out, label='Внешний потенциал')
plt.axvline(x=a, color='k', linestyle='--', label='Радиус сферы (a)')
plt.xlabel
plt.ylabel
plt.title
plt.legend()
plt.grid(True)
plt.show()