对于作业,我需要在代码中创建以下项的偏导数:
f(X)= -exp(x - y^2 + xy)
g(X)= cosh(y) + x - 2
我对x和y取了上面的偏导数:
df/dx = (1 + y) * -1 * exp(x - y^2 + xy)
df/dy = (-2*y + x) * -1 * (exp(x - y^2 + xy)
dg/dx = 1
dg/dy = sinh(y)
我使用了以下代码:
def f (x, y) :
return -1*np.exp(x-y*y + x*y)
def g (x, y) :
return np.cosh(y) + x - 2
# Next their derivatives, YOU SHOULD IMPLEMENT THESE
def dfdx (x, y) :
return (1+y) * -1*f(x, y)
def dfdy (x, y) :
return (-2*y + x) * -1 *f(x, y)
def dgdx (x, y) :
return 1
def dgdy (x, y) :
return np.sinh(y)
将其插入优化功能时,会被告知我写错了功能,但不确定在哪里?