Results 1 to 8 of 8

Thread: square root

  1. #1

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Smile square root

    Is there a formula to find out square roots, or do you just use approximate divisions to work out the answer?

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  2. #2
    Lively Member
    Join Date
    Jun 2001
    Location
    Banana Republic
    Posts
    115

  3. #3

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    thanks

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  4. #4
    Aurilus
    Guest
    Try the Sqr() function - although maybe that is only a VB6 function.. I never needed to use it before I got VB6 so I'm not sure

    - Aurilus

  5. #5

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by Aurilus
    Try the Sqr() function - although maybe that is only a VB6 function.. I never needed to use it before I got VB6 so I'm not sure

    - Aurilus
    Yeah, I know all about the functions, but I was looking for an explanation on how they work. And that link seems to explain it.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  6. #6
    Addicted Member
    Join Date
    Feb 2001
    Posts
    198
    Here is a manual method example, it’s similar to long division :

    Pick a number, any number 18.6624

    Draw a line above the number and a vertical line down the left hand side.

    Starting at the decimal point, draw vertical lines grouping the numbers into pairs.

    |---|-|---|------------
    |18|.|66|24

    Take the approx square root of the leftmost pair of digits 18, which is 4.

    Write this number above the leftmost pair (add the decimal point if it’s next) this is the partial answer.

    4 .
    |---------------------
    |18|.|66|24


    Write the square of this partial answer under the first pair and subtract.

    4 .
    |---------------------
    |18|.|66|24
    |16
    | --
    | 2

    Bring down the next pair of digits

    4 .
    |---------------------
    |18|.|66|24
    |16
    | --
    | 266


    Multiply the partial answer by 2 and write it next to the new line, with an underline to the right of it.

    4 .
    |---------------------
    |18|.|66|24
    |16
    | --
    8_ | 266

    Find a digit (x) that will replace the underline so that (10 times double the partial answer plus x) multiplied by x is less than the present remainder
    or in this case so that x times eighty-x is less that 266.
    4 . 3
    |---------------------
    |18|.|66|24
    |16
    | --
    83 | 266
    | 249
    add this new digit to the partial answer on the top line and multiply the 83 by the new digit.

    Subtract this new value from the line above it and bring down the next pair of digits

    4 . 3
    |---------------------
    |18|.|66|24
    |16
    | --
    83 | 266
    | 249
    |------
    | 1724


    Again, multiply the partial answer by 2 and leave an underline to the right

    4 . 3
    |---------------------
    |18|.|66|24
    |16
    | --
    83 | 266
    | 249
    |------
    86_ | 1724

    Find a replacement for the underline similar to above, add this to the partial answer, and multiply

    (the 862 by 2)


    4 . 3 2
    |---------------------
    |18|.|66|24
    |16
    | --
    83 | 266
    | 249
    |------
    862 | 1724
    | 1724
    ----------
    0

    Subtract and continue until you have enough digits in the partial answer for your purposes.


    In this case ( as I cheated) the result of the subtraction is zero so the answer is a proper square root.

  7. #7
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Successive approximations.

    See the following thread.

    http://www.vbforums.com/showthread.p...threadid=65366

    It describes the successive approximation method usually used for computer square root functions. It shows an example, and describes the use of the general method for solving other problems. I do not think it is difficult to understand. Briefly, square root is calculated as follows.
    • Guess at the square root. Suppose we wanted the square root of 100 and guessed twenty.
    • Divide the number by the guess: 100/20 = 5
    • Average the guess and the quotient: (5 + 20) / 2 = 12.5
    • Use the average as the next guess.
    • Continue the above until two successive guesses are almost equal.
    When I was in elementary school, I got in trouble for using the above method instead of the method taught which looks a bit like division (see post by Starman). If you are good at making a first guess, the successive approximation method is faster.

    When computers were very slow and had few resources, a minor problem was determining a first guess at a solution to an equation when successive approximation methods were to be used.

    For example, consider a first guess at the square root of a number.
    • To minimize the code required, some programs used the number itself as the first approximation. This resulted in a lot of iterations and a slower program.
    • A better approximation is the average of the number and one. For the square root of five you would use 3, which is a lot better the above approximation of five (the number itself). For the square root of .5, you would use .75 (this is pretty good).
    • For very large or very small numbers, the above is not very good, but if calculating a first guess takes more time than 3-4 iterations of the successive approximation method, you might not save much.
    Does anybody know what algorithm is used for a first guess in modern systems?
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  8. #8
    jim mcnamara
    Guest
    Some use tables. The fastest ones generally do use tables.

    here is a discussion of it:
    http://www.azillionmonkeys.com/qed/sqroot.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width