From eab11a89ba866bbfd72114bf6415847d93ea17e0 Mon Sep 17 00:00:00 2001 From: Vinay Reddy Date: Sat, 7 Oct 2023 21:38:59 +0530 Subject: [PATCH] Create newton_method_sqrt.py --- newton_method_sqrt.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 newton_method_sqrt.py diff --git a/newton_method_sqrt.py b/newton_method_sqrt.py new file mode 100644 index 0000000..0fea469 --- /dev/null +++ b/newton_method_sqrt.py @@ -0,0 +1,11 @@ +def newton_sqrt(number, iterations=10): + # Step 1: Initialize the initial guess for the square root (x). + x = 1.0 + + # Step 2: Perform the Newton-Raphson method for a specified number of iterations. + for _ in range(iterations): + # Step 3: Calculate the new approximation for the square root using the formula. + x = 0.5 * (x + number / x) + + # Step 4: Return the final approximation for the square root. + return x