Reputation: 71
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.00645+(x_r)^2), 4.3*x_i^2]])
return self.T
part_real=0.532
part_imag=1.2
R_0 = fmin(A.minim,part_real,part_imag)
but i got this error:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy/optimize/optimize.py", line 268, in function_wrapper
return function(x, *args)
TypeError: minim() argument after * must be a sequence, not float
I tried to use something else like minimize but the same error appear. Thank you.
Upvotes: 0
Views: 1299
Reputation: 54340
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]])
return self.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.
Upvotes: 2