# sqrt

## Syntax

``B = sqrt(X)``

## Description

example

````B = sqrt(X)` returns the square root of each element of the array `X`. For the elements of `X` that are negative or complex, `sqrt(X)` produces complex results.The `sqrt` function’s domain includes negative and complex numbers, which can lead to unexpected results if used unintentionally. For negative and complex numbers ```z = u + i*w```, the complex square root `sqrt(z)` returns`sqrt(r)*(cos(phi/2) + 1i*sin(phi/2))`where `r = abs(z)` is the radius and ```phi = angle(z)``` is the phase angle on the closed interval ```-pi <= phi <= pi```.If you want negative and complex numbers to return error messages rather than return complex results, use `realsqrt` instead.```

## Examples

collapse all

Create a row vector containing both negative and positive values.

`X = -2:2`
```X = 1×5 -2 -1 0 1 2 ```

Compute the square root of each element of `X`.

`Y = sqrt(X)`
```Y = 1×5 complex 0.0000 + 1.4142i 0.0000 + 1.0000i 0.0000 + 0.0000i 1.0000 + 0.0000i 1.4142 + 0.0000i ```

## Input Arguments

collapse all

Input array, specified as a numeric scalar, vector, matrix, or multidimensional array.

Data Types: `single` | `double`
Complex Number Support: Yes

collapse all

### IEEE Compliance

For real inputs, `sqrt` has a few behaviors that differ from those recommended in the IEEE®-754 Standard. In particular, negative inputs produce complex results instead of `NaN`.

MATLAB® IEEE

`sqrt(-0)`

`0`

`-0`

`sqrt(X)` for ```X < 0```

`0+sqrt(-X)*i`

`NaN`

## Version History

Introduced before R2006a