Skip to content Skip to sidebar Skip to footer

Use Of Fmin In Python

I'm trying to use fmin to minize my function: def minim(self,x_r,x_i): self.a=complex(3,4)*(3*np.exp(1j*self.L_ch)) x = x_r + x_i self.T=np.array([[0.0,2.0*self.a],[(0.

Solution 1:

You are not using fmin correctly.

scipy.optimize.fmin(func, x0, args=(), xtol=0.0001, ftol=0.0001, maxiter=None, maxfun=None, full_output=0, disp=1, retall=0, callback=None). If you want to optimize for both x_r and x_i, you should pass them together as x0. The way you are doing it now passes part_imag as args, which should be a sequence, not a scalar. That's why your get an exception

Without an reproducible example, I guess you need to change your code to:

def minim(self,p):
    x_r=p[0]
    x_i=p[1]
    self.a=complex(3,4)*(3*np.exp(1j*self.L_ch))
    x = x_r + x_i
    self.T=np.array([[0.0,2.0*self.a],[(0.00645+(x_r)^2), 4.3*x_i^2]])
    returnself.T

part_real=0.532
part_imag=1.2
R_0 = fmin(A.minim,[part_real,part_imag])

And see if it works.

Also your x seems never get used.

Post a Comment for "Use Of Fmin In Python"