Built on Facts

Sunday Function

Here’s a very simple function:


You give it a positive real number, it gives you the square root. It maps 81 to 9, 100 to 10, 2 to 1.414…, and so on and so forth. It’s pretty much the only one-argument function that’s built into most pocket calculators, which says something about its utility and ubiquity. But let’s say we did want to come up with an easy way to get approximate square roots. Maybe our calculator is broken, or (much more likely) maybe we’re looking for an analytic approximation that’s easier to deal with than the square root in and of itself. To generate our approximation, let’s take a look at the function:


It starts off rather dramatically curved, but as x gets larger and larger, the increasing value of the square root smooths out and begins to look more and more like a straight line of constant slope. We can imagine that if we drew a straight line tangent to this curve at a point of exactly known square root, we could use that line to estimate the value of the square root in the immediate neighborhood of this point. For instance, we know that the square root of 64 is 8. Therefore if we draw a line just touching that point on the graph, we might just have developed a pretty good approximation for finding the square root of numbers near 64. Actually carrying this out, we have a graph that looks like this:


To actually do anything useful with this, we need to find the equation of that line. Using the point-slope form of the equation of a line, we know that our line will have the following form. I’ll explain the constants after I print it:


The line itself is a function, and since f is already taken we’ll call it g. The constant m is just the slope of the line, and the constants x0 and y0 are the coordinates of the point on the original curve to which the line is tangent. (x0 = 64 and y0 = 8, because 8 is the square root of 64)

The slope m is the part that we don’t yet know a priori. To find it we need a little bit of calculus. Calculus tells us that the slope of the tangent line is equal to the derivative of the original function, evaluated at that point. So calculating the derivative, we find that:


Putting x = 64 in that expression, we find that our particular m is 1/16. Therefore for numbers near 64, their square root is roughly g(x):


Let’s check it. Plugging in (say) x = 65, we get that the square root of 65 is about 8.0625. The actual answer is 8.062257748… Which is pretty close.

The procedure works anywhere, you are by no means limited to the vicinity of x = 64. You can redo the calculation and put the tangent line anywhere convenient. For instance, if you want to calculate square roots in the vicinity of x = 100, just recognise that the new x0 = 100, the new y0 = 10, and the new m = 1/(2*10) = 1/20. In fact it will turn out that the higher x0, the broader the range of accuracy of this approximation about that point.

I admit this application for a linear approximation is a little contrived. But it does work, and if it didn’t physics would have been very hard-pressed indeed to have developed past the pre-Newton dark ages.


  1. #1 Alex Besogonov
    December 7, 2009

    And of course, no discussion about square roots is complete without mentioning fast inverse sqrt algorithm from the original Quake: http://en.wikipedia.org/wiki/Fast_inverse_square_root

  2. #2 Eric Lund
    December 7, 2009

    There is a method for calculating square roots longhand (see, e.g., this explanation with example). The method appears to be equivalent to iterated application of the technique you describe above.

  3. #3 CCPhysicist
    December 7, 2009

    It may be contrived, but the point about how the range of validity of the linear approximation depends on where you start has an application to lots of areas of physics.

    In mechanics, the reason we never noticed the need for relativity until well after the theory was developed was that the approximation we were using for the kinetic energy followed the true function until well past where any experiments were being done.

    Elsewhere, it is common to use a linear approximation that is valid around, say, room temperature when working with empirically determined ‘functions’. Knowing where your model breaks down is critical.

  4. #4 Zippy the Pinhead
    December 7, 2009

    The y-intercept (x=0) of g(x) is y sub 0/2, a quick hint for drawing your tangent line.

  5. #5 Jesse Pino
    December 7, 2009

    Um, this is just a two term Taylor Series, and is by no means unique to sqrt(x).

  6. #6 Brad
    December 7, 2009

    I guess this is how I do it in my head, but, rather than deriving the method as you did, I just used the formula from jr. high algebra X^2=(A+B)^2=(A^2+2AB+B^2). Find the closest A^2, assume B^2 to be insignificant, and divide the difference of X^2-A^2 by 2A. This is one of the ways I keep myself amused. Sad.

  7. #7 Matt Springer
    December 7, 2009

    Indeed that’s true by definition, Jesse. But in my experience a concrete example is a lot more interesting than abstract generalities. If I were teaching a class instead of writing a blog, I’d take the more general approach. Here however, that’s likely to bore everyone to death. That’s what textbooks are for.

    Brad, that’s a lot of things but “sad” ain’t among them. It’s an excellent way to demonstrate the power of this method without invoking calculus at all. You could easily adapt it for other roots as well via the binomial theorem.

  8. #8 Ambitwistor
    December 7, 2009

    Newton’s iterative method for square roots is also cool.

    r’ = (r + x/r)/2