Guest User

Untitled

a guest
Jun 5th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. import numpy as np
  2. from scipy.optimize import curve_fit
  3.  
  4. def hyperbola(x, s_1, s_2, o_x, o_y, c):
  5. # x > Input x values
  6. # s_1 > slope of line 1
  7. # s_2 > slope of line 2
  8. # o_x > x offset of crossing of asymptotes
  9. # o_y > y offset of crossing of asymptotes
  10. # c > curvature of hyperbola
  11.  
  12. b_2 = (s_1 + s_2) / 2
  13. b_1 = (s_2 - s_1) / 2
  14.  
  15. return o_y + b_1 * (x - o_x) + b_2 * np.sqrt((x - o_x) ** 2 + c ** 2 / 4)
  16.  
  17. min_fit = np.array([-3.0, 0.0, -2.0, -10.0, 0.0])
  18. max_fit = np.array([0.0, 3.0, 3.0, 0.0, 10.0])
  19. guess = np.array([-2.5/3.0, 4/3.0, 1.0, -4.0, 0.5])
  20.  
  21. vars, covariance = curve_fit(f=hyperbola, xdata=n_step, ydata=n_mean, p0=guess, bounds=(min_fit, max_fit))
Add Comment
Please, Sign In to add comment