# How to calculate a square root? Техника

If N is an approximation to  , a better approximation can be found by using the Taylor series of the square root function:

According to historian of mathematics D.E. Smith, Aryabhata’s method for finding the square root was first introduced in Europe by Cataneo—in 1546.

An unknown Babylonian mathematician somehow correctly calculated the square root of 2 to three sexagesimal «digits» after the 1, but it is not known exactly how. The Babylonians knew how to approximate a hypotenuse using

The denominator in the fraction corresponds to the nth root. In the case above the denominator is 2, hence the equation specifies that the square root is to be found. The same identity is used when computing square roots with logarithm tables or slide rules.

## Lucas sequence method

the Lucas sequence of the first kind Un(P,Q) is defined by the recurrence relations:

and the characteristic equation of it is:

it has the discriminant   and the roots:

so when we want  , we can choose   and  , and then calculate   using   and  for large value of  .
The most effective way to calculate   and  is:

then when  :

## A two-variable iterative method

The initialization step of this method is

Then,   (while  ).

The convergence of  , and therefore also of  , is quadratic.

The proof of the method is rather easy. First, rewrite the iterative definition of   as

Then it is straightforward to prove by induction that

This can be used to construct a rational approximation to the square root by beginning with an integer. If   is an integer chosen so   is close to  , and   is the difference whose absolute value is minimized, then the first iteration can be written as:

Using the same example as given with the Babylonian method, let   Then, the first iteration gives

Likewise the second iteration gives

Notation for the (principal) square root of .

For example, = 5, since 25 = 5 ⋅ 5, or (5 squared).

Square roots of negative numbers can be discussed within the framework of complex numbers. More generally, square roots can be considered in any context in which a notion of the «square» of a mathematical object is defined. These include function spaces and square matrices, among other mathematical structures.

In layman language square root can be defined as A square root of a number is a value that, when multiplied by itself, gives the number. In Python or any other Programming Language to calculate the square root of a number, we have different methods. And In this tutorial, we will try to cover all the methods to calculate the square root of a number.

## Iterative methods for reciprocal square roots

The first way of writing Goldschmidt’s algorithm begins

(typically using a table lookup)

until   is sufficiently close to 1, or a fixed number of iterations. The iterations converge to

Note that it is possible to omit either   and   from the computation, and if both are desired then   may be used at the end rather than computing it through in each iteration.

A second form, using fused multiply-add operations, begins

until   is sufficiently close to 0, or a fixed number of iterations. This converges to

Square roots of positive numbers are not in general rational numbers, and so cannot be written as a terminating or recurring decimal expression. Therefore in general any attempt to compute a square root expressed in decimal form can only yield an approximation, though a sequence of increasingly accurate approximations can be obtained.

where and 10 are the natural and base-10 logarithms.

as it allows one to adjust the estimate by some amount and measure the square of the adjustment in terms of the original estimate and its square. Furthermore,   when is close to 0, because the tangent line to the graph of   at  , as a function of alone, is  . Thus, small adjustments to can be planned out by setting   to , or  .

That is, if an arbitrary guess for   is x0, and xn + 1 = (xn + a/xn) / 2, then each xn is an approximation of   which is better for large n than for small n. If a is positive, the convergence is quadratic, which means that in approaching the limit, the number of correct digits roughly doubles in each next iteration. If , the convergence is only linear.

Using the identity

The time complexity for computing a square root with n digits of precision is equivalent to that of multiplying two n-digit numbers.

Another useful method for calculating the square root is the shifting nth root algorithm, applied for .

If you have studied calculus, you undoubtedly learned the power rule to find the derivative of basic functions. However, when the function contains a square root or radical sign, such as , the power rule seems difficult to apply. Using a simple exponent substitution, differentiating this function becomes very straightforward. You can then apply the same substitution and use the chain rule of calculus to differentiate many other functions that include radicals.

200 characters left «Heron’s method» redirects here. For the formula used to find the area of a triangle, see Heron’s formula.

More precisely, if is our initial guess of   and is the error in our estimate such that S = (x+ ε)2, then we can expand the binomial

and solve for the error term

Therefore, we can compensate for the error and update our old estimate as

It can also be represented as:

This algorithm works equally well in the -adic numbers, but cannot be used to identify real square roots with -adic square roots; one can, for example, construct a sequence of rational numbers by this method that converges to +3 in the reals, but to −3 in the 2-adics.

To calculate , where = 125348, to six significant figures, use the rough estimation method above to get

Therefore, ≈ 354.045.

Semilog graphs comparing the speed of convergence of Heron’s method to find the square root of 100 for different initial guesses. Negative guesses converge to the negative root, positive guesses to the positive root. Note that values closer to the root converge faster, and all approximations are overestimates. In the SVG file, hover over a graph to display its points.

Then it can be shown that

And thus that

and consequently that convergence is assured, and quadratic.

#### Worst case for convergence

Thus in any case,

Rounding errors will slow the convergence. It is recommended to keep at least one extra digit beyond the desired accuracy of the being calculated to minimize round off error.

Given a number N, the task is to write a C program to find the square root of the given number N.

Input: N = 12 Output: 3.464102

Input: N = 16 Output: 4

Method 1: Using inbuilt sqrt() function: The sqrt() function returns the sqrt of any number N.

Below is the implementation of the above approach:

int N = 12;

printf(«%f «, findSQRT(N));

Time complexity: O(logN), as the inbuilt sqrt() function take log(n)Auxiliary space: O(1)

Method 2: Using Binary Search: This approach is used to find the square root of the given number N with precision upto 5 decimal places.

float findSQRT(int number)

int start = 0, end = number;

mid = (start + end) / 2;

ans = mid;

start = mid + 1;

end = mid — 1;

float increment = 0.1;

ans += increment;

ans = ans — increment;

increment = increment / 10;

Method 3: Using log2(): The square-root of a number N can be calculated using log2() as:

Let d be our answer for input number N, then Apply log2() both sides   d = pow(2, 0.5*log2(n))

Methods of computing square roots are numerical analysis algorithms for approximating the principal, or non-negative, square root (usually denoted , , or ) of a real number. Arithmetically, it means given , a procedure for finding a number which when multiplied by itself, yields ; algebraically, it means a procedure for finding the non-negative root of the equation ; geometrically, it means given two line segments, a procedure for constructing their geometric mean.

The continued fraction representation of a real number can be used instead of its decimal or binary expansion and this representation has the property that the square root of any rational number (which is not already a perfect square) has a periodic, repeating expansion, similar to how rational numbers have repeating expansions in the decimal notation system.

The method employed depends on what the result is to be used for (i.e. how accurate it has to be), how much effort one is willing to put into the procedure, and what tools are at hand. The methods may be roughly classified as those suitable for mental calculation, those usually requiring at least paper and pencil, and those which are implemented as programs to be executed on a digital electronic computer or other computing device. Algorithms may take into account convergence (how many iterations are required to achieve a specified precision), computational complexity of individual operations (i.e. division) or iterations, and error propagation (the accuracy of the final result).

Procedures for finding square roots (particularly the square root of 2) have been known since at least the period of ancient Babylon in the 17th century BCE. Heron’s method from first century Egypt was the first ascertainable algorithm for computing square root. Modern analytic methods began to be developed after introduction of the Arabic numeral system to western Europe in the early Renaissance. Today, nearly all computing devices have a fast and accurate square root function, either as a programming language construct, a compiler intrinsic or library function, or as a hardware operator, based on one of the described procedures.

Abramowitz, Miltonn; Stegun, Irene A. (1964). Handbook of mathematical functions with formulas, graphs, and mathematical tables. Courier Dover Publications. p. 17. ISBN 978-0-486-61272-0.

Bailey, David; Borwein, Jonathan (2012). «Ancient Indian Square Roots: An Exercise in Forensic Paleo-Mathematics» . American Mathematical Monthly. Vol. 119, no. 8. pp. 646–657. Retrieved .

Campbell-Kelly, Martin (September 2009). «Origin of Computing». Scientific American. 301 (3): 62–69. Bibcode:2009SciAm.301c..62C. doi:10.1038/scientificamerican0909-62. JSTOR 26001527. PMID 19708529.

Cooke, Roger (2008). Classical algebra: its nature, origins, and uses. John Wiley and Sons. p. 59. ISBN 978-0-470-25952-8.

Fowler, David; Robson, Eleanor (1998). «Square Root Approximations in Old Babylonian Mathematics: YBC 7289 in Context» . Historia Mathematica. 25 (4): 376. doi:.

Gower, John C. (1958). «A Note on an Iterative Method for Root Extraction». The Computer Journal. 1 (3): 142–143. doi:.

Guy, Martin; UKC (1985). «Fast integer square root by Mr. Woo’s abacus algorithm (archived)». Archived from the original on 2012-03-06.

Heath, Thomas (1921). A History of Greek Mathematics, Vol. 2. Oxford: Clarendon Press. pp. 323–324.

Lomont, Chris (2003). «Fast Inverse Square Root» .

Markstein, Peter (November 2004). Software Division and Square Root Using Goldschmidt’s Algorithms . 6th Conference on Real Numbers and Computers. Dagstuhl, Germany. CiteSeerX .

Piñeiro, José-Alejandro; Díaz Bruguera, Javier (December 2002). «High-Speed Double-Precision Computationof Reciprocal, Division, Square Root, and Inverse Square Root». IEEE Transactions on Computers. 51 (12): 1377–1388. doi:10.1109/TC.2002.1146704.

Sardina, Manny (2007). «General Method for Extracting Roots using (Folded) Continued Fractions». Surrey (UK).

Simply Curious (5 June 2018). «Bucking down to the Bakhshali manuscript». Simply Curious blog. Retrieved .

Steinarson, Arne; Corbit, Dann; Hendry, Mathew (2003). «Integer Square Root function».

Wilkes, M.V.; Wheeler, D.J.; Gill, S. (1951). The Preparation of Programs for an Electronic Digital Computer. Oxford: Addison-Wesley. pp. 323–324. OCLC 475783493.

Algebra is an important topic of mathematics. A square root is an operation that is used in many formulas and different fields of mathematics. This article is about square root and square root formula. The square root of a number is a number squaring which gives the original number. There are multiple square root formulas that are discussed in this article with their problems.

The square root of a number is a number squaring which gives the original number. It is that factor of the number that when squared gives the original number. It is the value of power 1/2 of that number. The square root of a number is represented as √.

Example: Square root of 9 ⇒ √9 = ± 3

Here, 32 = 9

(-3)2 = 9

The number inside the square root is called radicand and the square root symbol is called radical.

Methods for finding the square root of a number

There are two methods for finding the square roots of a number that are highly used in mathematics. These are discussed below.

### Prime Factorization Method

Prime factorization is a method in which a number is represented in the form of the product of prime numbers.  Then the square root of the number is fined according to the given concept.

To find the square root using the prime factorization method:

Step 1: Represent the number in its prime factors using prime factorization method.

Step 2: Form the pair of the same factors.

Step 3:Take one factor from each pair and then, find the products of all the factors obtained by taking one factor from each pair.

Step 4:The resultant product is the square root of the number.

Example for Prime Factorization Method:

### Long Division Method

Steps to find the square root of a number using the long division method:

Example: Find the square root of 256 using the long division method.

Step 1. Divide the number into pairs starting from one place. For example, pairs starting from one place:= 2, 56 Step 2. After dividing the digits into pairs, start from the leftmost pair or digit. The largest number whose square is just less than or equal to the first pair or digit is taken as the divisor and also the quotient. In the above example, the largest number whose square is just less than 2 is 1. So, the divisor is 1 and the quotient is also 1. Step 3. Subtract the square of the divisor from the first pair or digit and bring the next pair down to the right of the reminder to get the new dividend. In the above example 2 – 1 = 1 then, we bring the next pair i.e. 56 down and the new dividend becomes 156. Step 4. Now, the new divisor is obtained by adding the previous divisor and the previous quotient digit and concatenating it with a suitable digit which is also taken as the next digit of the quotient, chosen in a way that the product of the new divisor and this new digit in quotient is equal to or just less than the new dividend. In the above example, the previous divisor is 1 and the previous quotient digit is 1 and their addition gives 2 which is the new divisor. Now, we have to choose a digit so that the product of the new divisor and the new digit in the quotient is equal to or less than the new dividend i.e. 26 is the new divisor and 6 in the new digit which is concatenated with the previous quotient. Now, the current quotient is 16. Step 5. Repeat steps 2, 3, and 4 till all the pairs have been taken. Now, the resultant quotient is the square root of the given number. In the above example, all pairs have been taken, and hence, the square root of the number 256 is 16. ### Table for Square and Square root of first ten natural numbers

The square root of a number has the exponent 1/2. The square root formula is used to find the square root of a number.

Square Root Formula :      √x = x1/2

### Sample Problems

Question 1: Find the sum: 5√3 + 6√12

5√3 + 6√12 = 5√3 + 6(√(4 × 3)

= 5√3 + 6 × √4 × √3

= 5√3 + 6 ×2√3

= 5√3 + 12√3

Question 2: Evaluate:  √64 – √25

√64 – √25 = √(8 × 8)  – √(5 × 5 )

= 8 – 5 = 3

Question 3: Evaluate: √63 / √28

√63 / √28 = √(7 × 9 )/ √(7 × 4 )

= √(9 /4)

= √9 / √4

Question 4: Evaluate: 5 /√15

5 /√15 = (5 /√15)×(√15 /√15 )

Question 5: Evaluate: 4 / (5 + √6)

= (20 – 4√6) / (25 – 6)

= (20 – 4√6) / 19

Question 6: Evaluate : 7 / (8 – √10)

= (56 + 7√10) / (64 – 10)

= (56 + 7√10) / 54

Question 7: Evaluate : (2 +√5) / (4 – √2)

In this tutorial, we are going to discuss the different ways to calculate square root in Python.

## What is a square root?

In this method, we will define our own function to find the square root of a number. And to calculate the square root of a number we will be using the exponent operator (**) in Python.

The defined function will take a number as an argument and return the square root of the number if it’s positive else it will print a warning. Let’s implement this in Python code.

Square root of number 441: 21.0
Square root of number 0.81: 0.9
Square root of number 6.25: 2.5
Square root of number 634: 25.179356624028344
Square root of negative number does not exist!

## Using the sqrt() function

In Python, the sqrt() function is a predefined function that is defined in the math module. The sqrt() function returns the square root of the number passed as an argument. Let’s see how we can use the built-in sqrt() function in a Python program.

Square root of number 121: 11.0
Square root of number 0.49: 0.7
Square root of number 4.41: 2.1
Square root of number 265: 16.278820596099706

NOTE: If a negative number is passed as an argument to the built-in sqrt() function then it will throw a math domain error. Let’s see an example.

# Import Python math module
import math as m

# Call the predefined sqrt() function
# to calculate the square root of a negative number
m.sqrt(-125) math domain error: sqrt()

## Using the pow() function

In this method to calculate square root, we will be using the built-in pow() function. In Python, the pow() function is a predefined function that is defined in the math module. The pow() function takes two arguments one is base and the other is the exponent/power and returns the square root of the number (base) passed as the first argument. To calculate the square root the exponent/power argument is fixed to 0.5. Let’s see how we can use the built-in pow() function in a Python program.

Square root of number 625: 25.0
Square root of number 0.64: 0.8
Square root of number 1.21: 1.1
Square root of number 7: 2.6457513110645907

NOTE: Here also if a negative number is passed as an argument to the built-in pow() function then it will throw a math domain error. Let’s see an example.

# Import Python math module
import math as m

# Call the predefined pow() function
# to calculate the square root of a negative number
m.pow(-121, 0.5) math domain error: pow()

## Using built-in np. sqrt() function

In this method of finding the square root, we will be using the built-in np.sqrt() function. In Python, the np.sqrt() function is a predefined function that is defined in the numpy module. The np.sqrt() function returns a numpy array where each element is the square root of the corresponding element in the numpy array passed as an argument. Let’s see how we can use the built-in np.sqrt() function in a Python program.

NOTE: If there is a negative number in the numpy array and it is passed to the built-in np.sqrt() function then it will throw a RuntimeWarning saying that an invalid value is encountered in sqrt. And set a nan value at the place of the square root of the negative element in the returned numpy array.

Дополнительно:  Синий экран

## Conclusion

Any number which can be expressed as the product of two whole equal numbers is classified as a perfect square. For example, 25 can be written as 5*5 hence 25 is a perfect square.

### Algorithm To Check

Enter the Number: 81
81 is a perfect square

## Calculating Square Root in Python Using Loop

Please Enter any Postive Integer : 5
Enter Exponent Value to the power raise to : 3
The Result of 5 Power 3 = 125

## Sqrt() Function in Numpy to Calculate Square Root

numpy is a third party library and module which provides calculations about matrix, series, big data, etc. Numpy also provides the sqrt() and pow() functions and we can use these function to calculate square root.

import numy
numpy.sqrt(9)
//The result is 3

numpy.pow(9,1/2)
//The result is 3

## Square roots of positive integers

A positive number has two square roots, one positive, and one negative, which are opposite to each other. When talking of the square root of a positive integer, it is usually the positive square root that is meant.

The square roots of an integer are algebraic integers—more specifically quadratic integers.

The square root of a positive integer is the product of the roots of its prime factors, because the square root of a product is the product of the square roots of the factors. Since   only roots of those primes having an odd power in the factorization are necessary. More precisely, the square root of a prime factorization is

### As decimal expansions

As with before, the square roots of the perfect squares (e.g., 0, 1, 4, 9, 16) are integers. In all other cases, the square roots of positive integers are irrational numbers, and therefore have non-repeating digits in any standard positional notation system.

The square roots of small integers are used in both the SHA-1 and SHA-2 hash function designs to provide nothing up my sleeve numbers.

### As periodic continued fractions

One of the most intriguing results from the study of irrational numbers as continued fractions was obtained by Joseph Louis Lagrange c.. Lagrange found that the representation of the square root of any non-square positive integer as a continued fraction is periodic. That is, a certain pattern of partial denominators repeats indefinitely in the continued fraction. In a sense these square roots are the very simplest irrational numbers, because they can be represented with a simple repeating pattern of integers.

## Square roots of matrices and operators

Quadratic irrationals (numbers of the form  , where a, b and c are integers), and in particular, square roots of integers, have periodic continued fractions. Sometimes what is desired is finding not the numerical value of a square root, but rather its continued fraction expansion, and hence its rational approximation. Let S be the positive number for which we are required to find the square root. Then assuming a to be a number that serves as an initial guess and r to be the remainder term, we can write   Since we have  , we can express the square root of S as

By applying this expression for   to the denominator term of the fraction, we have

For , the value of   is 1, so its representation is:

Proceeding this way, we get a generalized continued fraction for the square root as

Step 2 is to reduce the continued fraction from the bottom up, one denominator at a time, to yield a rational fraction whose numerator and denominator are integers. The reduction proceeds thus (taking the first three denominators):

Finally (step 3), divide the numerator by the denominator of the rational fraction to obtain the approximate value of the root:

rounded to three digits of precision.

The actual value of is 1.41 to three significant digits. The relative error is 0.17%, so the rational fraction is good to almost three digits of precision. Taking more denominators gives successively better approximations: four denominators yields the fraction  , good to almost 4 digits of precision, etc.

In general, the larger the denominator of a rational fraction, the better the approximation. It can also be shown that truncating a continued fraction yields a rational fraction that is the best approximation to the root of any fraction with denominator less than or equal to the denominator of that fraction — e.g., no fraction with a denominator less than or equal to 70 is as good an approximation to as 99/70.

## Nth roots and polynomial roots

A cube root of   is a number   such that  ; it is denoted

If is an integer greater than two, a th root of   is a number   such that  ; it is denoted

Given any polynomial , a root of is a number such that p(y) = 0. For example, the th roots of are the roots of the polynomial (in )

Abel–Ruffini theorem states that, in general, the roots of a polynomial of degree five or higher cannot be expressed in terms of th roots.

## Negative or complex square

If S < 0, then its principal square root is

If S = a+bi where a and b are real and b ≠ 0, then its principal square root is

is the modulus of S. The principal square root of a complex number is defined to be the root with the non-negative real part.

## Properties and uses

The graph of the function f(x) = √x, made up of half a parabola with a vertical directrix

The principal square root function   (usually just referred to as the «square root function») is a function that maps the set of nonnegative real numbers onto itself. In geometrical terms, the square root function maps the area of a square to its side length.

The square root of x is rational if and only if x is a rational number that can be represented as a ratio of two perfect squares. (See square root of 2 for proofs that this is an irrational number, and quadratic irrational for a proof for all non-square natural numbers.) The square root function maps rational numbers into algebraic numbers, the latter being a superset of the rational numbers).

For all real numbers x,

(see absolute value)

For all nonnegative real numbers x and y,

The square root function is continuous for all nonnegative x, and differentiable for all positive x. If f denotes the square root function, whose derivative is given by:

The square root of a nonnegative number is used in the definition of Euclidean norm (and distance), as well as in generalizations such as Hilbert spaces. It defines an important concept of standard deviation used in probability theory and statistics. It has a major use in the formula for roots of a quadratic equation; quadratic fields and rings of quadratic integers, which are based on square roots, are important in algebra and have uses in geometry. Square roots frequently appear in mathematical formulas elsewhere, as well as in many physical laws.

## In integral domains, including fields

Each element of an integral domain has no more than 2 square roots. The difference of two squares identity u2 − v2 = (u − v)(u + v) is proved using the commutativity of multiplication. If and are square roots of the same element, then u2 − v2 = 0. Because there are no zero divisors this implies or u + v = 0, where the latter means that two roots are additive inverses of each other. In other words if an element a square root of an element exists, then the only square roots of are and . The only square root of 0 in an integral domain is 0 itself.

In a field of characteristic 2, an element either has one square root or does not have any at all, because each element is its own additive inverse, so that −u = u. If the field is finite of characteristic 2 then every element has a unique square root. In a field of any other characteristic, any non-zero element either has two square roots, as explained above, or does not have any.

Given an odd prime number , let q = pe for some positive integer . A non-zero element of the field with elements is a quadratic residue if it has a square root in . Otherwise, it is a quadratic non-residue. There are (q − 1)/2 quadratic residues and (q − 1)/2 quadratic non-residues; zero is not counted in either class. The quadratic residues form a group under multiplication. The properties of quadratic residues are widely used in number theory.

Python math module deals with mathematical functions and calculations. Function sqrt() in the math module is used to calculate the square root of a given number.

### Syntax

num –  Here num can be any positive number whom square root you want.

### Return Value of sqrt() Function

sqrt() method in Python will return the square root of the given number in floating-point. If the value is less than 0 then it will return Runtime Error.

### Python sqrt() Function Compatibility

Let’s see some examples to calculate the Python Square Root using sqrt() function.

Example 1: Calculating Square Root of a Positive Integer

import math
print(«The square root of 25 is»,math.sqrt(64))

The square root of 25 is 8.0 Example 2: Calculating Square Root of a Floating Point Number

import math
print(«The square root of 9.9 is:», math.sqrt(12.9))

The square root of 9.9 is: 3.591656999213594

Example 3: Calculating Square Root of 0

import math
print(«The square root of 0 is»,math.sqrt(0))

The square root of 0 is 0.0

Example 4: Calculating Square Root of a Negative Number

import math
print(«The square root of -16 is»,math.sqrt(-16))

So, when x<0 it does not execute instead generates a ValueError.

Example 5: Calculating Square Root of Boltzmann Constant

Square root of Boltzmann constant:3.715707900252655e-12

Unlike in an integral domain, a square root in an arbitrary (unital) ring need not be unique up to sign. For example, in the ring   of integers modulo 8 (which is commutative, but has zero divisors), the element 1 has four distinct square roots: ±1 and ±3.

Another example is provided by the ring of quaternions   which has no zero divisors, but is not commutative. Here, the element −1 has infinitely many square roots, including , , and . In fact, the set of square roots of −1 is exactly

A square root of 0 is either 0 or a zero divisor. Thus in rings where zero divisors do not exist, it is uniquely 0. However, rings with zero divisors may have multiple square roots of 0. For example, in   any multiple of is a square root of 0.

Дополнительно:  Не включается ноутбук acer: инструкция для пользователя

## Calculating Square Root in Python Using ** Operator

** operator is exponent operator. a**b (a raised to the power b).

### Steps to Find Square Root in Python Using ** Operator

Example 1: Calculating Square Root of a Number Using ** Operator

def sqrt(n):
if n < 0:
return
else:
return n**0.5

print(sqrt(61))

## Different Ways to Calculate Square Root in Python

Generally, we have ways to calculate the square root in Python which are mentioned below:

## Calculating Square Root Using pow()

In this section, we are going to use the pow() built-in method to calculate the square root in Python.

Let us understand how does pow() function work in Python.

The pow() method takes 2 parameters, the first parameter is the numerical value, and the second parameter is the power of the numerical value. If we have a look at it, then you’ll notice that it is similar the way we have calculated the square root in the above examples.

pow(x,y)  # where y is the power of x or x**y

Example: Calculating Square Root of a Number Using pow()

Please Enter any numeric Value: 69
The Square Root of a Given Number 69.0 = 8.306623862918075

pow() is also a predefined method to find out the power of a number, it takes two arguments as input, first is the number itself and the second one is the power of that number. The program is same as the first program where we’re using (**) sign to find out the square root but the only difference is this that here we’re using a predefined method pow() instead of  (**) sign to get the power of that number.

## Square roots of negative and complex numbers

First leaf of the complex square root

Second leaf of the complex square root

Using the Riemann surface of the square root, it is shown how the two leaves fit together

The square of any positive or negative number is positive, and the square of 0 is 0. Therefore, no negative number can have a real square root. However, it is possible to work with a more inclusive set of numbers, called the complex numbers, that does contain solutions to the square root of a negative number. This is done by introducing a new number, denoted by i (sometimes by j, especially in the context of electricity where «i» traditionally represents electric current) and called the imaginary unit, which is defined such that i2 = −1. Using this notation, we can think of i as the square root of −1, but we also have (−i)2 = i2 = −1 and so −i is also a square root of −1. By convention, the principal square root of −1 is i, or more generally, if x is any nonnegative number, then the principal square root of −x is

The right side (as well as its negative) is indeed a square root of −x, since

For every non-zero complex number z there exist precisely two numbers w such that w2 = z: the principal square root of z (defined below), and its negative.

### Principal square root of a complex number

To find a definition for the square root that allows us to consistently choose a single value, called the principal value, we start by observing that any complex number   can be viewed as a point in the plane,   expressed using Cartesian coordinates. The same point may be reinterpreted using polar coordinates as the pair   where   is the distance of the point from the origin, and   is the angle that the line from the origin to the point makes with the positive real ( ) axis. In complex analysis, the location of this point is conventionally written   If

The principal square root function is holomorphic everywhere except on the set of non-positive real numbers (on strictly negative reals it is not even continuous). The above Taylor series for   remains valid for complex numbers   with

The above can also be expressed in terms of trigonometric functions:

where is the sign of (except that, here, sgn(0) = 1). In particular, the imaginary parts of the original number and the principal value of its square root have the same sign. The real part of the principal value of the square root is always nonnegative.

For example, the principal square roots of are given by:

where   and  .

A similar problem appears with other complex functions with branch cuts, e.g., the complex logarithm and the relations logz + logw = log(zw) or log(z*) = log(z)* which are not true in general.

if the branch includes +i or

if the branch includes −i, while the right-hand side becomes

where the last equality,   is a consequence of the choice of branch in the redefinition of √.

## Calculating Square Root in Python Using cmath Module

The cmath module is used to calculate the square root in python of Real or Complex number.

Example: Calculating Square Root of a Number Using cmath

The square root of (1+2j) is 1.272+0.786j

In this program, we use the sqrt() function in the cmath (complex math) module. Notice that we have used the eval() function instead of float() to convert complex number as well. Also, notice the way in which the output is formatted.

To differentiate the square root of x using the power rule, rewrite the square root as an exponent, or raise x to the power of 1/2. Find the derivative with the power rule, which says that the inverse function of x is equal to 1/2 times x to the power of a-1, where a is the original exponent. In this case, a is 1/2, so a-1 would equal -1/2. Simplify the result. To use the chain rule to differentiate the square root of x, read on!

Thanks to all authors for creating a page that has been read 285,801 times.

## Approximations that depend on the floating point representation

A number is represented in a floating point format as   which is also called scientific notation. Its square root is   and similar formulae would apply for cube roots and logarithms. On the face of it, this is no improvement in simplicity, but suppose that only an approximation is required: then just   is good to an order of magnitude. Next, recognise that some powers, , will be odd, thus for 3141.59 = 3.1415910 rather than deal with fractional powers of the base, multiply the mantissa by the base and subtract one from the power to make it even. The adjusted representation will become the equivalent of 31.415910 so that the square root will be 10.

A table with only three entries could be enlarged by incorporating additional bits of the mantissa. However, with computers, rather than calculate an interpolation into a table, it is often better to find some simpler calculation giving equivalent results. Everything now depends on the exact details of the format of the representation, plus what operations are available to access and manipulate the parts of the number. For example, Fortran offers an EXPONENT(x) function to obtain the power. Effort expended in devising a good initial approximation is to be recouped by thereby avoiding the additional iterations of the refinement process that would have been needed for a poor approximation. Since these are few (one iteration requires a divide, an add, and a halving) the constraint is severe.

So for a 32-bit single precision floating point number in IEEE format (where notably, the power has a bias of 127 added for the represented form) you can get the approximate logarithm by interpreting its binary representation as a 32-bit integer, scaling it by  , and removing a bias of 127, i.e.

For example, 1.0 is represented by a hexadecimal number 0x3F800000, which would represent   if taken as an integer. Using the formula above you get  , as expected from  . In a similar fashion you get 0.5 from 1.5 (0x3FC00000).

/* Assumes that float is in the IEEE 754 single precision floating point format */

/* Convert type, preserving bit pattern */

* ((((val.i / 2^m) — b) / 2) + b) * 2^m = ((val.i — 2^m) / 2) + ((b + 1) / 2) * 2^m)

* b = exponent bias
* m = number of mantissa bits

/* Subtract 2^m. */
/* Divide by 2. */
/* Add ((b + 1) / 2) * 2^m. */

/* Interpret again as float */

The three mathematical operations forming the core of the above function can be expressed in a single line. An additional adjustment can be added to reduce the maximum relative error. So, the three operations, not including the cast, can be rewritten as

### Reciprocal of the square root

/* The next line can be repeated any number of times to increase accuracy */

## Geometric construction of the square root

The square root of a positive number is usually defined as the side length of a square with the area equal to the given number. But the square shape is not necessary for it: if one of two similar planar Euclidean objects has the area a times greater than another, then the ratio of their linear sizes is  .

A square root can be constructed with a compass and straightedge. In his Elements, Euclid (fl. 300 BC) gave the construction of the geometric mean of two quantities in two different places: Proposition II.14 and Proposition VI.13. Since the geometric mean of a and b is  , one can construct   simply by taking .

The construction is also given by Descartes in his La Géométrie, see figure 2 on page 2. However, Descartes made no claim to originality and his audience would have been quite familiar with Euclid.

Another method of geometric construction uses right triangles and induction:   can be constructed, and once   has been constructed, the right triangle with legs 1 and   has a hypotenuse of  . Constructing successive square roots in this manner yields the Spiral of Theodorus depicted above.

So in this tutorial, we tried to cover how to calculate Square Root In Python.We Discussed all the methods and techniques by which you can calculate square root.

If you have still any doubts or suggestions. Do let us know in the comment section below.

Оцените статью 