Created
December 14, 2021 12:30
-
-
Save dadyarri/2f90bee721616670d9a273c42b044f61 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 func(x): # Подставьте вашу функцию | |
return ... | |
def main(): | |
a = 5.0 # Границы | |
b = 25.0 | |
tolerance = 0.00001 # Точность | |
iterations = ... # Число итераций | |
i = 0 | |
while i <= iterations: | |
c = (a + b) / 2.0 | |
if (func(a) * func(c)) < 0: | |
b = c | |
else: | |
a = c | |
i += 1 | |
print(f"Итерация: {i - 1}, Границы {(a, b)}. Корень: {c}, Значение функции {func(c)}") | |
if abs((a - b) / 2.0) < tolerance: | |
print(f'Корень после {i - 1} итерации - {c}') | |
else: | |
print('Нельзя достичь указанной точности в число итераций') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment