I have some function:
def V(x):
a = 0
g = 0
return 1/6*(3*x[0]**2+3*x[1]**2+6*x[0]**2*x[1]-2*x[1]**3)+a*(2*x[0]**6*(x[1]+1)+x[0]**4*x[1]**2*(2*x[1]+1)+x[0]**2*x[1]**4*(2*x[1]+1)+2*x[1]**6*(x[1]+1))+g*(x[0]**4*(x[1]-1)+x[0]**2*(x[1]-2)*x[1]**2-x[1]**4*(x[1]+1))
and I want to see when the partial derivatives with respect to x and y of V are 0. (x[0]
is x and x[1]
is y). I decided to use to scipy minimize function for this, so I came up with this function:
def LBFGS(x, y):
x0 = np.array([x, y])
res = minimize(V, x0, method='L-BFGS-B').x.tolist()
return res[0], res[1]
This takes in initial values and outputs the x and y coordinates of where V is minimized. Now the problem came when I started testing this function. One can easily check that (0, 0) is a place where the the partial derivatives with respect to x and y of V are 0. When I plugged in LBFGS(0, 0)
, it worked. However when I plugged in LBFGS(0, 0.1)
, I got (-4.9999383996738455e-09, 8.936905459196604e-08)
. Why am I getting weird answers when I should be getting (0, 0)?
Another example is when I plug in LBFGS(0, 1.01)
which should out put (0, 1) but I get
RuntimeWarning: overflow encountered in double_scalars
return 1/6*(3*x[0]**2+3*x[1]**2+6*x[0]**2*x[1]-2*x[1]**3)+a*(2*x[0]**6*(x[1]+1)+x[0]**4*x[1]**2*(2*x[1]+1)+x[0]**2*x[1]**4*(2*x[1]+1)+2*x[1]**6*(x[1]+1))+g*(x[0]**4*(x[1]-1)+x[0]**2*(x[1]-2)*x[1]**2-x[1]**4*(x[1]+1))
RuntimeWarning: invalid value encountered in double_scalars
return 1/6*(3*x[0]**2+3*x[1]**2+6*x[0]**2*x[1]-2*x[1]**3)+a*(2*x[0]**6*(x[1]+1)+x[0]**4*x[1]**2*(2*x[1]+1)+x[0]**2*x[1]**4*(2*x[1]+1)+2*x[1]**6*(x[1]+1))+g*(x[0]**4*(x[1]-1)+x[0]**2*(x[1]-2)*x[1]**2-x[1]**4*(x[1]+1))
(-138.778, 1.3510798882111488e+26)