Turn on thread page Beta
    • Thread Starter

    Not sure whether to post this here or in the maths forum, but I'll give you a go.

    I'm writing a very simple program to estimate the square root of a given number, using the Newton iteration method (http://en.wikipedia.org/wiki/Methods...wton_iteration). However, I can't think of a way to automatically make the initial estimate of the square root. I suppose the other option would be to have an arbitary estimation for all roots, and differ the number of iterations of the formula based on the magnitude of the number... maybe.

    Anyone have a suggestion?


    Why not use the first method under:
    Finding square roots using mental arithmetic

    // x is the number we're trying to approximate the square root of.

    // number of iterations
    iteration = 1

    // cumulative frequency
    cumulativeFrequency = x

    while ( cumulativeFrequency > (2*iteration - 1)) {
    cumulativeFrequency = cumulativeFrequency - (2*iteration - 1)
    iteration = iteration + 1

    print "Approximation to the square root of" + x + " is " + iteration

    That's a bit of pseudo pseudo-code.

    It subtracts the odd integers (going from 1, 3, 5, ...) until the number is less than the number you were planning to subtract from, e.g.:

    To find an approximation of the square root of 27:

    27 - 1 = 26
    26 - 3 = 23
    23 - 5 = 18
    18 - 7 = 11
    11 - 9 = 2

    We stop now since subtracting 11 from 2 would result in a negative number. Since we've gone through this cycle 5 times, the first digit of the square root of 27 is 5.
    • Thread Starter

    That's probably a far more suitable way actually, thanks.

    If you want an acurate way of doing this, there is a method rather like long division.


    First hit on google for "square root by hand". I used to know this. Now I don't. A good read none the less. As for whether this will produce less operations or not, my_clue == 0.
Submit reply
Turn on thread page Beta
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Updated: April 9, 2006
Do you have any savings?
Useful resources

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.