Advertisement
frolkin28

simple itration

Feb 23rd, 2020
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. from math import fabs, pow
  2.  
  3. e = 10e-3
  4.  
  5. def function(x):
  6.     return x ** 3 + x ** 2 - x - 0.5
  7.  
  8.  
  9. def simple_interation(x0, lamb):
  10.     iter = 1
  11.     x1 = x0 - lamb * function(x0)
  12.     print(x1)
  13.     while fabs(x1 - x0) > e:
  14.         iter += 1
  15.         x0 = x1
  16.         x1 = x0 - lamb * function(x0)
  17.         print(x1)
  18.     return x1
  19.  
  20.  
  21. def main():
  22.     dots = [-2, -0.5, 0,5]
  23.     lamb = [1/7, 0.01, 0.25]
  24.     root = simple_interation(dots[0], lamb[0])
  25.     print(root)
  26.     print()
  27.     root = simple_interation(dots[1], lamb[1])
  28.     print(root)
  29.     print()
  30.     root = simple_interation(dots[2], lamb[2])
  31.     print(root)
  32.  
  33. if __name__ == '__main__':
  34.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement