Posts

Showing posts with the label scipy

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,...

Conjugate transpose of self using numpy syntax

Conjugate transpose of self using numpy syntax I am trying to translate this MATLAB code into Python. The following is the code: Y=C*Up(:,1:p-1)'*Y; And this is my translation thus far: Y = C * Up[:, 1:p-1] * Y I am having trouble with the syntax for the conjugate transpose of self that is used in the MATLAb code. I am not certain that my first idea: Y = C * Up[:, 1:p-1].getH() * Y would be correct. Does anyone have any ideas? Can you provide sample inputs for the matrix (matrices)? – rahlf23 Jun 29 at 17:47 1:p-1 - remember, python indexing is 0 based, MATLAB 1 based. – hpaulj Jun 29 at 18:32 1:p-1 Is Up (possibly) complex? If not then plain transpose is enou...