我想对包含除法和一些三角函数的函数应用最小化,如下面的一段代码所示。但除以零时出现错误:
RuntimeWarning:在除法launch_new_instance()中遇到除以零
Lx=2592.
Ly=1936.
YA, XA = np.mgrid[0:Ly, 0:Lx]
XAvect=np.reshape(XA,(Lx*Ly))
YAvect=np.reshape(YA,(Lx*Ly))
#Initialization
x0 = 200.
y0 = 200.
KI = 100000.
T = 20.
A1 = 50.
A2 = 50.
def residual_V2west(vars, XA, YA, donnees):
KI = vars[0]
A1 = vars[1]
A2 = vars[2]
x0 = vars[3]
y0 = vars[4]
modeleV2 = KI/(G)*np.sqrt(np.sqrt((XA-x0)**2 + (YA-y0)**2)/(2*np.pi))*np.sin((np.arctan(((YA-y0)/(XA-x0))))/2)*(Kappa + 1 - 2*np.cos(np.arctan(((YA-y0)/(XA-x0)))/2)**2) + \
A1*np.sqrt((XA-x0)**2+(YA-y0)**2)*np.cos(np.arctan((YA-y0)/(XA-x0))) + A2
return (donnees-modeleV2)
from scipy.optimize import leastsq
vars = [KI, A1, A2, x0, y0]
out_V_west = sco.leastsq(residual_V2west, vars, args=(XAvect, YAvect, Vmvect),epsfcn=0.01)
print out_V_west