Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from scipy.optimize import curve_fit
- def hyperbola(x, s_1, s_2, o_x, o_y, c):
- # x > Input x values
- # s_1 > slope of line 1
- # s_2 > slope of line 2
- # o_x > x offset of crossing of asymptotes
- # o_y > y offset of crossing of asymptotes
- # c > curvature of hyperbola
- b_2 = (s_1 + s_2) / 2
- b_1 = (s_2 - s_1) / 2
- return o_y + b_1 * (x - o_x) + b_2 * np.sqrt((x - o_x) ** 2 + c ** 2 / 4)
- min_fit = np.array([-3.0, 0.0, -2.0, -10.0, 0.0])
- max_fit = np.array([0.0, 3.0, 3.0, 0.0, 10.0])
- guess = np.array([-2.5/3.0, 4/3.0, 1.0, -4.0, 0.5])
- 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