Created
May 8, 2023 05:27
-
-
Save okurka12/e680d24fbfa0497ff9223e4c257d1cbc to your computer and use it in GitHub Desktop.
overeni konvergence newtonovy numericke metody pro hledani korenu polynomu
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
from math import sin, cos | |
DEPTH = 9 | |
def f(x: float) -> float: | |
"""funkce f""" | |
return sin(x) - x**2 + 4 | |
def f_d(x: float) -> float: | |
"""derivace f""" | |
return cos(x) - 2*x | |
def recursive(depth: int, xn: float) -> float: | |
print(f"x_{DEPTH - depth} = {xn:.05f}, f({xn:.05f}) = {f(xn)}") | |
result = xn - f(xn)/f_d(xn) | |
if depth == 0: | |
return result | |
else: | |
return recursive(depth - 1, result) | |
return recursive() | |
#------------------------------------------------------------------- | |
recursive(DEPTH, -2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment