Skip to content

added type hints and doctests to arithmetic_analysis/newton_method.py #2259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 1, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update newton_method.py
  • Loading branch information
cclauss authored Aug 1, 2020
commit d55491a0c548a75300f1f6485b2ac0796b98c3f4
7 changes: 2 additions & 5 deletions arithmetic_analysis/newton_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@ def newton(function: RealFunc, derivative: RealFunc, starting_int: int,) -> floa
...
ZeroDivisionError: Could not find root
"""
prev_guess: float = starting_int
prev_guess float(starting_int)
while True:
try:
next_guess: float = prev_guess - function(prev_guess) / derivative(
prev_guess
)
next_guess = prev_guess - function(prev_guess) / derivative(prev_guess)
except ZeroDivisionError:
raise ZeroDivisionError("Could not find root")

if abs(prev_guess - next_guess) < 10 ** -5:
return next_guess
prev_guess = next_guess
Expand Down