Matrix square root (Error)

package
#1

Hi,

which command is for Matrix square root?

it worked before:

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


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

Best

#2

you can use just sqrt :

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 talking about that

#3

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

>> 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
#4

then, sqrt(complex(a))?

from the help ?sqrt:

  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.
2 Likes
#5

nice, good to know! thanks!

1 Like
#6

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
11 Likes