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

  1. Compute the square root of a positive number:

    julia> sqrt(25)
    5.0

    This example calculates the square root of the number 25, which is 5.

  2. Handle complex numbers:

    julia> sqrt(-4 + 3im)
    0.0 + 2.0im

    The sqrt function can handle complex numbers as well. In this example, it computes the square root of -4 + 3im, which is 0.0 + 2.0im.

  3. Use the prefix operator :
    julia> √9
    3.0

    The prefix operator is equivalent to calling the sqrt function. It can be used to compute the square root of a number. In this example, √9 returns 3.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.

*Required Field
Details

Checking you are not a robot: