Nepoma

4.1Rita

Nov 27th, 2023
1,461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. import numpy as np
  2. import scipy
  3. import matplotlib.pyplot as plt
  4.  
  5.  
  6. def model(x, t):
  7.     v0, r_in, r_out, c_in = 100, 1, 1, 0
  8.     v = v0 + (r_in - r_out) * t
  9.     d_v = r_in - r_out
  10.     return x * (d_v/v - r_out) + v * r_in * c_in
  11.  
  12.  
  13. x0 = 10
  14.  
  15. t_min = 0
  16. t_max = 5
  17. t = np.linspace(t_min, t_max)
  18. x = scipy.integrate.odeint(model, x0, t)
  19. inter_x = scipy.interpolate.CubicSpline(t, x)
  20. root = list(filter(lambda t_1: t_min <= t_1 <= t_max, inter_x.solve(10)[0]))
  21. print("Root is :", root)
  22. print("x(root) is: ", inter_x(root))
  23. plt.plot(t, x)
  24. plt.xlabel('time')
  25. plt.ylabel('x(t)')
  26. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment