Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import fabs, pow
- e = 10e-3
- def function(x):
- return x ** 3 + x ** 2 - x - 0.5
- def simple_interation(x0, lamb):
- iter = 1
- x1 = x0 - lamb * function(x0)
- print(x1)
- while fabs(x1 - x0) > e:
- iter += 1
- x0 = x1
- x1 = x0 - lamb * function(x0)
- print(x1)
- return x1
- def main():
- dots = [-2, -0.5, 0,5]
- lamb = [1/7, 0.01, 0.25]
- root = simple_interation(dots[0], lamb[0])
- print(root)
- print()
- root = simple_interation(dots[1], lamb[1])
- print(root)
- print()
- root = simple_interation(dots[2], lamb[2])
- print(root)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement