sqrt
sqrt(x)
Return $\sqrt{x}$. Throws DomainError for negative Real arguments. Use complex negative arguments instead. The prefix operator √ is equivalent to sqrt.
Examples
-
Compute the square root of a positive number:
julia> sqrt(25) 5.0This example calculates the square root of the number 25, which is 5.
-
Handle complex numbers:
julia> sqrt(-4 + 3im) 0.0 + 2.0imThe
sqrtfunction can handle complex numbers as well. In this example, it computes the square root of-4 + 3im, which is0.0 + 2.0im. - Use the prefix operator
√:julia> √9 3.0The prefix operator
√is equivalent to calling thesqrtfunction. It can be used to compute the square root of a number. In this example,√9returns3.0.
Common mistake example:
julia> sqrt(-9)
ERROR: DomainError with -9.0:
sqrt will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
In this example, a DomainError is thrown because the input -9 is a negative real number. To compute the square root of negative real numbers, use complex numbers instead by passing a complex argument, like sqrt(Complex(-9)).
See Also
abs2, beta, binomial, ceil, cell, cross, ctranspose, ctranspose!, cummin, cumprod, cumprod!, cumsum, cumsum!, cumsum_kbn, div, divrem, eigfact, eigfact!, eigmin, eps, erf, erfc, erfcinv, erfcx, erfi, erfinv, exp, exp10, exp2, expm1, exponent, factor, factorial, factorize, floor, gcd, invmod, log, log10, log1p, log2, logspace, max, min, mod, mod1, modf, next, nextpow, nextprod, num, primes, primesmask, prod, realmin, sqrt, sum!, sumabs, sumabs!, sumabs2, sumabs2!,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.