Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import numpy as np
- def F(x):
- return x*x-10*x+2
- a = 3
- b = 6
- eps = 0.01
- #метод поразрядного поиска
- h = 0.001
- flag = False
- x = []
- for i in np.arange(a, b, h):
- x.append(i)
- x.append(i + h)
- if F(x[-2]) < F(x[-1]):
- if h < eps and not flag:
- x_ans = x[-2]
- flag = True
- else:
- h /= -4
- y = [F(i) for i in x]
- plt.plot (x, y)
- plt.grid(True)
- plt.show()
- print("x* = ", x_ans, "\ny_min = ", F(x_ans))
- #метод дихотомии
- delta = eps/10
- h = (b-a)/2
- while h <= eps:
- x1 = (a+b-delta)/2
- x2 = (a+b+delta)/2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement