Advertisement
mirosh111000

8

Sep 17th, 2023
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. import numpy as np
  2. from scipy.integrate import odeint
  3. import matplotlib.pyplot as plt
  4.  
  5. def differential_equation(y, x):
  6.     dydx, d2ydx2, d3ydx3 = y[1], y[2], y[3]
  7.     d4ydx4 = y[0]**2 + 3 * x
  8.     return [dydx, d2ydx2, d3ydx3, d4ydx4]
  9.  
  10. y0 = [4, 2, 1, 0]
  11.  
  12. x_values = np.linspace(0, 1, 100)
  13. solution = odeint(differential_equation, y0, x_values)
  14. y_values = solution[:, 0]
  15.  
  16. plt.plot(x_values, y_values, label='y(x)')
  17. plt.xlabel('x')
  18. plt.ylabel('y')
  19. plt.legend()
  20. plt.grid()
  21. plt.title('Розв\'язок диференціального рівняння')
  22. plt.show()
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement