Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from matplotlib import pyplot as plt
- import numpy as np
- from scipy import optimize as opt
- f = lambda x: np.sin(x**2)-6*x+1
- phi = lambda x: (np.sin(x**2)+1)/6
- x = np.arange(0, 1, 0.1)
- plt.plot(x, f(x), x, np.zeros(len(x)))
- plt.show()
- def fixed_point_iter(f, x0, eps):
- x = x0
- while True:
- y = f(x)
- if abs(y - x) < eps:
- return y
- else:
- x = y
- my_sol = fixed_point_iter(phi, 2, 1e-6)
- print(my_sol)
- sc_sol = opt.root_scalar(f, method='brentq', bracket=[1, 2]).root
- print(sc_sol)
- print(abs(sc_sol - my_sol))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement