Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.90 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. from scipy.integrate import odeint
  3. import numpy as np
  4.  
  5. def trou_noir(M):
  6.     c = 1                      #vitesse de la lumière
  7.     G = 1                      #constante gravitation universelle
  8.     #M = 0.05                  #masse trou noir
  9.     rs = (2*G*M)/(c**2)        #rayon Schwarzschild
  10.    
  11.     for a in range(60):
  12.         h0 = 1.54 - 0.12*a              #hauteur initiale
  13.         d0 = 2                          #distance de référence
  14.         phi0 = np.arctan(h0/d0)         #angle initial
  15.         d = h0/(np.sin(phi0))           #distance au trou noir                  
  16.         alpha = phi0                    #l'angle alpha pour la direction initiale du rayon
  17.        
  18.         if h0 > 0:
  19.             phi = np.linspace(phi0,4*np.pi,1000)
  20.         else:
  21.             phi = np.linspace(phi0,phi0-4*np.pi,1000)
  22.        
  23.         def fonction(U,phi):       #définition de l'équa diff sous forme u'' = f(u,u')
  24.             (u, du) = U
  25.             return (du, 1.5 * rs * u**2 - u)
  26.        
  27.         U, dU = odeint(fonction, [1/d, 1/(d*np.tan(alpha))], phi).T
  28.         #résolution équa diff avec 2 conditions initiales u(0) et u'(0) en fonction de phi
  29.         R = 1/U
  30.        
  31.         x,y = R*np.cos(phi),R*np.sin(phi)
  32.        
  33.         xnew1 = []
  34.         ynew1 = []
  35.         condition = True
  36.        
  37.         for i in range(1000):
  38.             a,b=x[i],y[i]
  39.             if M==0:
  40.                 xnew1.append(a)
  41.                 ynew1.append(b)
  42.             if a<3 and a>-3 and b<3 and b>-3 and a**2 + b**2 > rs**2 and M!=0 and condition == True:
  43.                 xnew1.append(a)
  44.                 ynew1.append(b)
  45.             else:
  46.                 condition = False        
  47.         plt.plot(xnew1,ynew1)
  48.    
  49.     t = np.linspace(0,2*np.pi,100)
  50.     m = rs*np.cos(t)
  51.     n = rs*np.sin(t)
  52.     plt.plot(m,n)
  53.     plt.axis('equal')
  54.     plt.xlim(-1,1)
  55.     plt.ylim(-1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement