Is it possible to calculate a square root of an unknown number using only basic arithmetics?

176 Views Asked by At

Long story short: Trying to implement calculation of distance between 2 points using the formula:

$$z = \sqrt{(x_2 - x_1)^2 + (y_2- y_1)^2}$$

Is there a way to calculate $Z$ with only basic arithmetic functions? $X$ and $Y$ coordinates are positive integers on a 2D map.

2

There are 2 best solutions below

0
On

If you mean is there a formula in terms of (a finite number) of arithmetic operations that will produce the square root, than the answer is no. If the numbers $x_i$ and $y_i$ are rational numbers, then any formula using only arithmetic operations will (if well defined) have as value a rational number. But the desired square root can very well not be a rational number in this case.

0
On

You only need addition and division to compute the square root of a number. The method I will demonstrate is called Average and Divide and can be taught to an elementary school student.

As an example, we will compute $\sqrt{5}$.

  1. Guess at a solution. I will guess $2$. If your guess is way off, you will still get the right answer.
  2. Divide your guess into the number whose square root you are calculating. For this example, we get $5\div 2=2.5$
  3. Take the average of the result of step $2$ and your last guess to get $\frac{2+2.5}{2}=2.25$
  4. Return to step $1$ using our new value, $2.25$ as a guess. Continue these steps until the number you divide into $5$ is the same, up to the precision you seek, as the result of the division.

For this case, the sequence of guesses we get are $$2, 2.25, 2.236$$

You can check that $(2.236)^2=4.999696$. If you need more precision you just keep repeating the procedure.