Submitted by Mikinak77 t3_zy5yuj in explainlikeimfive
Target880 t1_j244m57 wrote
There is multiple way to calculate a square root https://en.wikipedia.org/wiki/Methods_of_computing_square_roots The simples to understand is iterative methods. The general idea is make a guess and then improve it.
without using any specific algorithm let's try to calculate the square root of 26. Let's find a to large and to small number and test the average of them. If the average is to small replace the smaller number, if it is to larger replace the larger
Let's first guess at 5 5 ^(2) =25, that is too low lets call it S
The second guess at 6 6^(2) =36 is to large let's call it L .
Let's try the midpoint (S+ L)/2 =(5+6)/2 = 5.5 and 5.5^2 =30.25 which is to large so replace S with it.
The next average is (5+5.5)/2=5.25 Let's repeat it in the table below. I rounded all numbers to 6 or less decimals
S L (S+L)/2 ((S+L)/2)^2
5 6 5.5 30.25 To large
5 5.5 5.25 27.5625 To large
5 5.25 5.125 26.265625 To large
5 5.125 5.0625 25.628906 To small
5.0625 5.125 5.09375 25.946289 To small
5.09375 5.125 5.109375 26.105716 To large
5.09375 5.109375 5.101563 26.02594 To large
5.09375 5.101563 5.097659 25.986102 To small
5.097659 5.101563 5.099611 26.006032 To large
5.097659 5.099611 5.098635 25.996079 To small
5.098635 5.099611 5.099123 26.001055 To large
5.098635 5.099123
Let's stop at this point. We can see that the square root is in between 5.098635 and 5.099123 so we know it to be two decimals as 5.09. We could continue this forever and get closer and closer. Many roots like this will have an infinite number of decimals so wee needs to stop.
The algorithm above is not an especially efficient one because it converges quite slowly but it is a good example of an iterative way do numerical find a solution to an equation.
The guesses I made were so you quickly get some decimals correctly. But you can pick a conservative guess like 1 and the number /2 that will work for any number we look for a root for that is larger than 1
Newton-Rapson https://en.wikipedia.org/wiki/Newton%27s_method method is faster, but exactly why you choose that formulais a lot harder to explain.
Let's call x the guess and a number we look for the root of in this case a=26. The next guess can be calculated 1/2( x + a/x) let's start with 5 and calculate the next number as 1/2 (5+26/5) = 5.1 . The next step is 1/2 (5.1+26/5.1)
I added a space among the decimal at the point it is longer accurate
5
5.1
5.099019 6078431372549019607843137254901960784313725490196078431372
5.09901951359278 57010906650681807043140270913210506275188406452756
5.099019513592784830028224109022 8563911005788636011794938296893309
5.099019513592784830028224109022781989563770946099596407584970804 9
The square root is
5.0990195135927848300282241090227819895637709460995964075849708044...
The number of accurate decimals doubles in each step. That is a very efficient way to find a square root of a number
Viewing a single comment thread. View all comments