0
$\begingroup$

I've been asked this question by my teacher. The function I'm talking about is the following:

SqrtFloor[n_Integer] := 
 Module[{a = n, b = Quotient[n + 1, 2]}, 
  While[b < a, a = b; b = Quotient[a^2 + n, 2 a]]; a]

I understand the code, but I don't know what is the mathematical concept behind it. Why does it return the largest integer less than or equal to √n?

$\endgroup$
2
$\begingroup$

This is a discretized version of Newton's Method where f(x) = x^2 - a, which has a zero at x = Sqrt[a]. Wikipedia With initial guess x = n, (x^2 + n)/(2 x) decreases at each step until x <= Sqrt(n).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.