def 158 f0 40 return sum for in range f0 def grad 158 return np array

1
2
3
4
5
6
7
def f(x, n=2, a=158, b=2, f0=40):
return sum([a * (x[i] ** 2 - x[i + 1]) ** 2 + b * (x[i] - 1) ** 2 for i in range(0, n - 1)]) + f0
def grad(x, a=158, b=2):
return np.array([4 * a * x[0] * (x[0] ** 2 - x[1]) + 2 * b * (x[0] - 1),
-2 * a * (x[0] ** 2 - x[1])])