All problems
Newton Step for the Square Root
Problem
One Newton step for computing the square root of a solves z^2 - a = 0 and gives z_new = z - (z^2 - a) / (2z).
Given a > 0 and a nonzero current estimate x, return the updated estimate.
Hint
The update averages the estimate with a / x, which converges quadratically.
Test cases
case 1
in: [2,1]
expected: 1.5
case 2
in: [4,2]
expected: 2
case 3
in: [9,2]
expected: 3.25
case 4
in: [1,1]
expected: 1
Starter codePython
def newton_sqrt_step(a, x):
# Your code here
pass4 test cases · run your code against them in the editor