Fit data within two function bounds
Fit data within two function bounds I have a set of data which, according to a theory, is bounded within two bounds. The upper bound is : f(x)=1/x (x<0.5) The lower bound is : f(x)=1+1/(2x)(x<0.5) The data I got is close to one of these two bounds. I’m trying to find a function to describe these data. But if I use normal fitting method, the fitted curve can be outside of these two bounds. How can I force my fitted curve between these two bounds by using scipy.curve_fit? I'm trying to use Pade approximant to do the fitting, the code I'm using is following: def pfuncp_3_1(x, a0, a1, a2, a3, b1): p1 = ((a0+a1*x+a2*x**2+a3*x**3)*(1+b1*x)**(-1)-1-1/(2*x)<0)*2.0 p2 = ((a0+a1*x+a2*x**2+a3*x**3)*(1+b1*x)**(-1)-1/x>0)*2.0 return (a0+a1*x+a2*x**2+a3*x**3)*(1+b1*x)**(-1) + p1 + p2 def ffuncp_3_1(x, a0, a1, a2, a3, b1): return (a0+a1*x+a2*x**2+a3*x**3)*(1+b1*x)**(-1) def data_fitter(pfunc, ffunc, fit_x, fit_y, new_x): popt, pcov = opt.curve_fit(pfunc, fit_x,...
