-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
41 lines (32 loc) · 796 Bytes
/
main.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import math
from optimization import cbpd as op
# The function
def fn(p):
x = p[0]
y = p[1]
return -math.sin(x)*math.sin(y)
# Partial derivative to X
def dx_fn(p):
x = p[0]
y = p[1]
return -math.cos(x)*math.sin(y)
# Partial derivative to Y
def dy_fn(p):
x = p[0]
y = p[1]
return -math.cos(y)*math.sin(x)
initial_point = [2.5, 0.8]
func = op.Function(fn, initial_point)
# Converge numerically
try:
point = func.converge_numerically()
print("[ Numerically] - Converge point: {} ".format(point))
except Exception as err:
print(err)
# Converge analytically
func.derivatives = [dx_fn, dy_fn]
try:
point = func.converge_analytically()
print("[ Analytically ] - Converge point: {} ".format(point))
except Exception as err:
print(err)