fork download
  1. import numpy as np
  2.  
  3. import matplotlib.pyplot as plt
  4.  
  5. # Constants
  6. G = 1
  7. M = 1
  8. a = 1
  9.  
  10. # Radial coordinate
  11. r = np.linspace(0, 2, 500)
  12.  
  13. # Potential inside the sphere (r <= a)
  14. def potential_inside(r):
  15. return -G * M * (3 * a**2 - r**2) / (2 * a**3)
  16.  
  17. # Potential outside the sphere (r > a)
  18. def potential_outside(r):
  19. return -G * M / r
  20.  
  21. # Calculate potentials
  22. potential_in = potential_inside(r[r <= a])
  23. potential_out = potential_outside(r[r > a])
  24.  
  25. # Plotting
  26. plt.figure(figsize=(10, 6))
  27. plt.plot(r[r <= a], potential_in, label='Внутренний потенциал')
  28. plt.plot(r[r > a], potential_out, label='Внешний потенциал')
  29. plt.axvline(x=a, color='k', linestyle='--', label='Радиус сферы (a)')
  30. plt.xlabel
  31. plt.ylabel
  32. plt.title
  33. plt.legend()
  34. plt.grid(True)
  35. plt.show()
Success #stdin #stdout #stderr 3.4s 68340KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Fontconfig error: No writable cache directories