sqrtm

Matrix square root: a matrix X with X*X equal to A.

Category: Mathematics > Linear Algebra

Syntax

X = sqrtm(A)

Returns the principal square root of the square matrix A.

Description

This is a matrix function, not an element-wise one: sqrtm(A) differs from sqrt(A), which takes the square root of each entry. It is computed from the Schur form of A by a recurrence on the triangular factor.

A matrix with a negative real eigenvalue has no real square root, so the result is complex. If A is singular, the root may not exist or may be inaccurate, and a warning is issued.

Input arguments

A
Square numeric matrix.

Output arguments

X
Matrix with X*X = A, whose eigenvalues have nonnegative real part. It may be complex even for a real A.

Example

Matrix versus element-wise root

A = [4 0; 0 9];
X = sqrtm(A)
X*X
B = [2 1; 1 2];
sqrtm(B)^2
Output
X = 2×2

     2     0
     0     3
ans = 2×2

     4     0
     0     9
ans = 2×2

    2.0000    1.0000
    1.0000    2.0000

See also

sqrt expm logm funm schur