用python 写一段实现函数f(x,y)=(x+2y)^2在 (1,2) 点处的梯度的代码
时间: 2023-05-31 15:03:15 浏览: 64
采用梯度方法 python
import autograd.numpy as np
from autograd import grad
def f(x, y):
return (x**(2*y))**2
grad_f = grad(f)
x = 1
y = 2
grad_val = grad_f(x, y)
print("Gradient of f(x,y) at point (1,2) is:", grad_val)
阅读全文