Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8a0fd69

Browse files
committed
Flip sign in Newton-Raphson to match the common presentation.
1 parent e9e5d54 commit 8a0fd69

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Lib/statistics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,8 +1717,8 @@ def _newton_raphson(f_inv_estimate, f, f_prime, tolerance=1e-12):
17171717
def f_inv(y):
17181718
"Return x such that f(x) ≈ y within the specified tolerance."
17191719
x = f_inv_estimate(y)
1720-
while abs(diff := y - f(x)) > tolerance:
1721-
x += diff / f_prime(x)
1720+
while abs(diff := f(x) - y) > tolerance:
1721+
x -= diff / f_prime(x)
17221722
return x
17231723
return f_inv
17241724

0 commit comments

Comments
 (0)