-
-
Save undrcrxwn/caed49abae35cc8087e957ef9490b93f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def f(x): | |
return math.exp(-2 * x) - 3 * x ** 3 | |
a = 0.4976 | |
b = 0.49761 | |
eps = 1e-12 | |
k = 0 | |
print("a = ", a) | |
print("b = ", b) | |
print("eps = ", eps) | |
k = 1 | |
x = (a+b)/2; | |
while (abs(b-a) >= eps) and (k<=1000): | |
x = (a+b)/2; | |
if f(x) == 0: | |
print("Найден точный корень. X = ", x) | |
print("Количество итераций k = ",k) | |
print("Проверка f(x) = ", f(x)) | |
break | |
elif f(a)*f(x) > 0: | |
a = x | |
else: | |
b = x | |
k += 1 | |
print("x = ", x) | |
print("Количество итераций k = ",k) | |
print("Проверка f(x) = ", f(x)) | |
if k>=1000: | |
print("Заданная точность не достигнута, превышен предел итераций") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment