Advertisement
svinoviteran

newtonSys

May 21st, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. import numpy as np
  2. def f(x):
  3.     return [np.sin(x[0] + x[1]) - 1.2 * x[0] + 0.1, x[0] ** 2 + x[1] ** 2 - 1]
  4.  
  5. def g(x):
  6.     return [[np.cos(x[0] + x[1]) - 1.2, np.cos(x[0] + x[1])],
  7.            [2 * x[0], 2 * x[1]]]
  8.  
  9. def Newts(x, f, g, eps):
  10.     k = 0
  11.     while (True):
  12.         x_ = x - np.linalg.inv(g(x)) @ f(x)
  13.         k += 1
  14.         if np.linalg.norm(x_ - x) < eps:
  15.             return x_, k
  16.         x = x_
  17.  
  18. x = [1, 0.7]
  19. print(g(x))
  20.  
  21.  
  22. ans = Newts(x, f, g, 1e-6, )
  23. print(ans)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement