Advertisement
mirosh111000

7

Sep 17th, 2023
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. import numpy as np
  2. from scipy.integrate import odeint
  3. import matplotlib.pyplot as plt
  4.  
  5. def system_of_equations(variables, t):
  6.     x, y, dxdt, dydt = variables
  7.     d2xdt2 = x**2 + y**2
  8.     d2ydt2 = x - np.cos(y)**2 + t
  9.     return [dxdt, dydt, d2xdt2, d2ydt2]
  10.  
  11.  
  12. initial_conditions = [2, 10, 1, 3]
  13.  
  14. t_span = np.linspace(0, 1, 1000)
  15.  
  16. solution = odeint(system_of_equations, initial_conditions, t_span)
  17.  
  18. x_values = solution[:, 0]
  19. y_values = solution[:, 1]
  20.  
  21. plt.plot(t_span, x_values, label='x(t)')
  22. plt.plot(t_span, y_values, label='y(t)')
  23. plt.legend()
  24. plt.grid()
  25. plt.title('Розв\'язок системи диференціальних рівнянь')
  26. plt.show()
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement