-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnewtonm.py
More file actions
36 lines (32 loc) · 762 Bytes
/
Copy pathnewtonm.py
File metadata and controls
36 lines (32 loc) · 762 Bytes
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
import numpy as np
from numpy.linalg import inv
from scipy import optimize as opt
import math
class NewtonMethod(object):
"""
Constructor Newton-Method
"""
def __init__ (self, f, fd, H, xk, eps):
self.fd = fd
self.H = H
self.xk = xk
self.eps = eps
self.f = f
return
"""
Newton-Method
"""
def work (self):
f = self.f
fd = self.fd
H = self.H
xk = self.xk
eps = self.eps
it = 0
#maxit = 10000
while (np.linalg.norm(fd(xk)) > eps): #and (it < maxit):
Hfd = inv(H(xk))@(fd(xk))
xk = xk - Hfd
it += 1
print("Log-Values(Newton): ", math.log10(f(xk)))
return xk, it