I am trying to use curve_fit
to fit some data. it is working great, I would just like to improve the fit with additional parameters to match assumptions (such as mechanical efficiency cannot be greater than 100% etc)
y_data = [0.90 0.90 0.90 0.90 0.90 0.90 0.90 1.30 1.30 1.30 1.30 1.20 1.65 1.65 1.65 1.65 1.65 1.65 1.80 1.80 1.80 1.80 1.80 1.80 1.80 1.80 1.80 3.50 6.60 6.60 6.70 6.70 6.70 6.70 6.70 8.50 12.70] # I am aware this does not have commas
x_data = [0.38 0.38 0.38 0.38 0.38 0.38 0.38 0.38 0.38 0.38 0.38 0.46 0.53 0.53 0.53 0.53 0.53 0.53 0.53 0.53 0.53 0.53 0.53 0.53 0.53 0.53 0.53 0.53 1.02 1.02 1.02 1.02 1.02 1.02 1.02 1.02 1.02] # ditto
def poly2(x, a, b, c): return a*x**2+ b*x+c
def poly3(x,a,b,c,d): return a*x**3+b*x**2+c*b*x+d
pars = fit(poly2, x_data, y_data, bounds=bounds)
But I would like to additionally specify bounds to relations between parameters eg.
B**2 -4*a*c > 0 #for poly2
b**2-3*a*c=0 #for poly3
To ensure that the fit has horizontal inflection.
Is there a way to achieve this?
Edit: I found this, it may help once I investigate:How do I put a constraint on SciPy curve fit?
How would this be done using lmfit as suggested?