from vector import Vec2d func_glob lambda x1_ x2_ x1_ x2_ 001 grad_x l

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from vector import Vec2d
func_glob = lambda x1_, x2_: x1_ * x2_
e = 0.001
grad_x = lambda x1_, x2_: x2_
grad_y = lambda x1_, x2_: x1_
def gradient_search(f, gradient_x, gradient_y):
xi = Vec2d(1, 1)
x_i1 = Vec2d(0, 0)
while True:
x_i1 = xi - lambda_() * Vec2d(gradient_x(xi.x, xi.y), gradient_y(xi.x, xi.y))
if x_i1 - xi <= e:
return x_i1
def lambda_():
return 1
print(gradient_search(func_glob, grad_x, grad_y))