fork download
  1. import numpy as np
  2. import scipy.optimize as opt
  3. import matplotlib.pyplot as plt
  4. import pandas as pd
  5.  
  6. # Define updated parameters
  7. mu = 0.3591178047 # Mass ratio of the secondary body
  8. mu3 = 6696.424814 # Mass ratio of the tertiary body
  9. R3 = 43.763984 # Distance of the tertiary body (canonical units)
  10.  
  11. # Define shi as a function of time
  12. def shi_function(t):
  13. shi_0 = np.pi / 2
  14. delta_n = 1 - n3 # Difference in angular speed
  15. return shi_0 + delta_n * t
  16.  
  17. # Corrected angular speed of m3 in canonical units (assuming shi = π/2 initially)
  18. shi_initial = np.pi / 2
  19. n3 = np.sqrt((1 - mu) / R3**3 + mu / (R3**2 + 1 - 2 * R3 * np.cos(shi_initial))**(3/2)) # Updated formula
  20.  
  21. # Define functions for distances (keeping x = 0)
  22. def r1(y, z):
  23. return np.sqrt(mu ** 2 + y ** 2 + z ** 2)
  24.  
  25. def r2(y, z):
  26. return np.sqrt((1 - mu) ** 2 + y ** 2 + z ** 2)
  27.  
  28. def r3(y, z, shi):
  29. return np.sqrt((R3 * np.cos(shi) - mu) ** 2 + y ** 2 + z ** 2)
  30.  
  31. # Define force balance equations with correction terms (x = 0)
  32. def lagrange_equations(vars, shi):
  33. y, z = vars
  34.  
  35. # Compute distances
  36. r1_val = r1(y, z)
  37. r2_val = r2(y, z)
  38. r3_val = r3(y, z, shi)
  39.  
  40. # Correction term (only in y direction, since x=0)
  41. correction_y = mu3 * ((1 - mu) * np.sin(shi) / R3**2 + mu * (R3 * np.sin(shi)) / (R3**2 + 1 - 2 * R3 * np.cos(shi))**(3/2))
  42.  
  43. # Force equations (Fx is removed because x = 0)
  44. Fy = -(1 - mu) * y / r1_val ** 3 - mu * y / r2_val ** 3 - mu3 * y / r3_val ** 3 - correction_y - y
  45. Fz = -(1 - mu) * z / r1_val ** 3 - mu * z / r2_val ** 3 - mu3 * z / r3_val ** 3
  46.  
  47. return [Fy, Fz]
  48.  
  49. # Generate initial guesses in y-z plane (setting x=0)
  50. initial_guesses = [
  51. (0.5, 0), (-0.5, 0), # Exploring points along y-axis
  52. (0, 0.5), (0, -0.5), (0.5, 0.5), (0.5, -0.5), (-0.5, 0.5), (-0.5, -0.5), # Exploring different y-z locations
  53. (0.5, 1), (0.5, -1), (-0.5, 1), (-0.5, -1)
  54. ]
  55.  
  56. # Compute Lagrange points for t = 0 and t = π/2
  57. time_values = [0, np.pi / 2]
  58. results = {}
  59.  
  60. for t in time_values:
  61. shi_t = shi_function(t)
  62. numerical_solutions = []
  63.  
  64. for guess in initial_guesses:
  65. sol = opt.fsolve(lagrange_equations, guess, args=(shi_t,))
  66. numerical_solutions.append(sol)
  67.  
  68. # Convert to DataFrame (Removing duplicates)
  69. df = pd.DataFrame(numerical_solutions, columns=['y', 'z'])
  70. df = df.round(6).drop_duplicates().reset_index(drop=True) # Remove duplicates and round
  71. results[t] = df
  72.  
  73. # Display results
  74. print(f"\nNumerical Lagrange Points for t = {t} (y-z Plane, x=0):")
  75. print(df)
  76.  
  77. # Plot the results
  78. fig = plt.figure(figsize=(7, 7))
  79. ax = fig.add_subplot(111)
  80.  
  81. ax.scatter(df['y'], df['z'], color='red', label='Lagrange Points')
  82. ax.scatter(0, 0, color='blue', marker='o', label='Primary Body')
  83. ax.scatter(0, 1, color='green', marker='o', label='Secondary Body')
  84.  
  85. ax.set_xlabel("Y")
  86. ax.set_ylabel("Z")
  87. ax.legend()
  88. ax.set_title(f"Lagrange Points in y-z Plane (t = {t}, x=0)")
  89. plt.show()
  90.  
Success #stdin #stdout #stderr 1.62s 97236KB
stdin
Standard input is empty
stdout
Numerical Lagrange Points for t = 0 (y-z Plane, x=0):
            y             z
0   23.715675  0.000000e+00
1  -23.751013  0.000000e+00
2   -3.495322  1.777442e+70
3   -3.495322 -1.251924e+70
4   -3.495322  5.186208e+68
5   -3.495322 -3.484809e+68
6   -3.495322  6.716980e+62
7   -3.495322 -2.075485e+69
8   -3.495322  5.306581e+71
9   -3.495322 -3.816433e+71
10  -3.495322  5.945609e+71
11  -3.495322 -5.946065e+71

Numerical Lagrange Points for t = 1.5707963267948966 (y-z Plane, x=0):
           y         z
0   1.021208  0.000000
1  -1.022275  0.000000
2  -0.017073  2.892487
3  -0.017073 -2.892487
4  -0.016801  2.889245
5  -0.016800 -2.889245
6  -0.016525  2.889342
7  -0.016525 -2.889343
8  -0.016840  2.888322
9  -0.016840 -2.888321
10 -0.016714  2.887826
11 -0.016714 -2.887826
stderr
/usr/local/lib/python3.7/dist-packages/scipy/optimize/minpack.py:162: RuntimeWarning: The iteration is not making good progress, as measured by the 
  improvement from the last ten iterations.
  warnings.warn(msg, RuntimeWarning)
/usr/local/lib/python3.7/dist-packages/scipy/optimize/minpack.py:162: RuntimeWarning: The number of calls to function has reached maxfev = 600.
  warnings.warn(msg, RuntimeWarning)
/usr/local/lib/python3.7/dist-packages/scipy/optimize/minpack.py:162: RuntimeWarning: The iteration is not making good progress, as measured by the 
  improvement from the last five Jacobian evaluations.
  warnings.warn(msg, RuntimeWarning)