Advertisement
svinoviteran

fixPoint

May 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. import numpy as np
  2.  
  3. f = lambda x: np.sin(x ** 2) - 6 * x + 1
  4. phi = lambda x: (np.sin(x ** 2) + 1) / 6
  5.  
  6. def fixed_point_iter(f, x0, eps):
  7.     x = x0
  8.     k = 0;
  9.     while True:
  10.         y = f(x)
  11.         k+=1;
  12.         if abs(y - x) < eps:
  13.             return y, k
  14.         else:
  15.             x = y
  16.  
  17.  
  18. my_sol, i = fixed_point_iter(phi, 0.5, 1e-6)
  19. print(my_sol)
  20. print(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement