# Matrix square root (Error)

**URL:** https://discourse.julialang.org/t/matrix-square-root-error/22556
**Category:** General Usage
**Tags:** package
**Created:** [March 31, 2019, 12:21am UTC](https://discourse.julialang.org/t/matrix-square-root-error/22556 "2019-03-31T00:21:14Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Aquaman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquaman/32/6586_2.png) [@Aquaman](https://discourse.julialang.org/u/Aquaman)
#### Post date: [March 31, 2019, 12:21am UTC](https://discourse.julialang.org/t/matrix-square-root-error/22556/1 "2019-03-31T00:21:14Z")

</div>

Hi,

which command is for Matrix square root?

it worked before:

```julia
julia> X = sqrtm([1.0 -0.9; -0.9 1.0])
2x2 Float64 Array:
  0.847316 -0.531089
 -0.531089 0.847316

```

But now in Julia 1.1.0

```julia

X = sqrtm([1.0 -0.9; -0.9 1.0])
ERROR: UndefVarError: sqrtm not defined

```

Best

---

<div class="post-metadata">

### Author: ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)
#### Post date: [March 31, 2019, 12:27am UTC](https://discourse.julialang.org/t/matrix-square-root-error/22556/2 "2019-03-31T00:27:08Z")

</div>

you can use just `sqrt` :

```julia
a = [1.0 -0.9; -0.9 1.0]
sqrt(a)
2×2 Array{Float64,2}:
  0.847316 -0.531089
 -0.531089 0.847316

```

I find [this post](https://discourse.julialang.org/t/status-of-exp-and-sqrt/4092) talking about that

---

<div class="post-metadata">

### Author: ![Aquaman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquaman/32/6586_2.png) [@Aquaman](https://discourse.julialang.org/u/Aquaman)
#### Post date: [March 31, 2019, 12:33am UTC](https://discourse.julialang.org/t/matrix-square-root-error/22556/3 "2019-03-31T00:33:37Z")

</div>

sqrt(a) and sqrtm(a) mean not the same, e.g.

```julia
>> sqrtm(a)

ans =

   0.5537 + 0.4644i 0.8070 - 0.2124i
   1.2104 - 0.3186i 1.7641 + 0.1458i

>> sqrt(a)

ans =

    1.0000 1.4142
    1.7321 2.0000

```

---

<div class="post-metadata">

### Author: ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)
#### Post date: [March 31, 2019, 12:36am UTC](https://discourse.julialang.org/t/matrix-square-root-error/22556/4 "2019-03-31T00:36:55Z")

</div>

then, `sqrt(complex(a))`?

from the help `?sqrt`:

```julia
  sqrt(A::AbstractMatrix)

  If A has no negative real eigenvalues, compute the principal matrix square root of A, that is the unique matrix X with eigenvalues having
  positive real part such that X^2 = A. Otherwise, a nonprincipal square root is returned.

  If A is symmetric or Hermitian, its eigendecomposition (eigen) is used to compute the square root. Otherwise, the square root is determined
  by means of the Björck-Hammarling method [^BH83], which computes the complex Schur form (schur) and then the complex square root of the
  triangular factor.

```

---

<div class="post-metadata">

### Author: ![Aquaman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aquaman/32/6586_2.png) [@Aquaman](https://discourse.julialang.org/u/Aquaman)
#### Post date: [March 31, 2019, 12:52am UTC](https://discourse.julialang.org/t/matrix-square-root-error/22556/5 "2019-03-31T00:52:51Z")

</div>

nice, good to know! thanks!

---

<div class="post-metadata">

### Author: ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)
#### Post date: [March 31, 2019, 9:49am UTC](https://discourse.julialang.org/t/matrix-square-root-error/22556/6 "2019-03-31T09:49:25Z")

</div>

This table may help clear up the confusion.

| | Matlab | Julia 0.4 | Julia 0.5 | Julia 0.6 | Julia 0.7 | Julia 1.x |
| --- | --- | --- | --- | --- | --- | --- |
| `sqrtm(a)` | M | M | M | M | M\* | E |
| `sqrt(a)` | P | P | P | P\* | M | M |
| `sqrt.(a)` | E | E | P | P | P | P |
| where | | | | | | |
| | | | | | | |
| — | — | | | | | |
| M | Matrix square root | | | | | |
| P | Pointwise square root | | | | | |
| \* | Deprecated | | | | | |
| E | Error | | | | | |
