sqrtm

Matrix square root

Description

example

X = sqrtm(A) returns the principal square root of the matrix A, that is, X*X = A.

X is the unique square root for which every eigenvalue has nonnegative real part. If A has any eigenvalues with negative real parts, then a complex result is produced. If A is singular, then A might not have a square root. If exact singularity is detected, a warning is printed.

[X,residual] = sqrtm(A) also returns the residual, residual = norm(A-X^2,1)/norm(A,1). This syntax does not print warnings if exact singularity is detected.

[X,alpha,condx] = sqrtm(A) returns stability factor alpha and an estimate of the matrix square root condition number of X in 1-norm, condx. The residual norm(A-X^2,1)/norm(A,1) is bounded approximately by n*alpha*eps and the 1-norm relative error in X is bounded approximately by n*alpha*condx*eps, where n = max(size(A)).

Examples

collapse all

Create a matrix representation of the fourth difference operator, A. This matrix is symmetric and positive definite.

A = [5 -4 1 0 0; -4 6 -4 1 0; 1 -4 6 -4 1; 0 1 -4 6 -4; 0 0 1 -4 6]
A = 5×5

5    -4     1     0     0
-4     6    -4     1     0
1    -4     6    -4     1
0     1    -4     6    -4
0     0     1    -4     6

Calculate the unique positive definite square root of A using sqrtm. X is the matrix representation of the second difference operator.

X = round(sqrtm(A))
X = 5×5

2    -1     0     0     0
-1     2    -1     0     0
0    -1     2    -1     0
0     0    -1     2    -1
0     0     0    -1     2

Consider a matrix that has four squareroots, A.

$A=\left[\begin{array}{cc}7& 10\\ 15& 22\end{array}\right]$

Two of the squareroots of A are given by Y1 and Y2:

${Y}_{1}=\left[\begin{array}{cc}1.5667& 1.7408\\ 2.6112& 4.1779\end{array}\right]$

${Y}_{2}=\left[\begin{array}{cc}1& 2\\ 3& 4\end{array}\right]$

Confirm that Y1 and Y2 are squareroots of matrix A.

A = [7 10; 15 22];
Y1 = [1.5667 1.7408; 2.6112 4.1779];
A - Y1*Y1
ans = 2×2
10-3 ×

-0.1258   -0.1997
-0.2995   -0.4254

Y2 = [1 2; 3 4];
A - Y2*Y2
ans = 2×2

0     0
0     0

The other two squareroots of A are -Y1 and -Y2. All four of these roots can be obtained from the eigenvalues and eigenvectors of A. If [V,D] = eig(A), then the squareroots have the general form Y = V*S/V, where D = S*S and S has four choices of sign to produce four different values of Y:

$S=\left[\begin{array}{cc}±0.3723& 0\\ 0& ±5.3723\end{array}\right]$

Calculate the squareroot of A with sqrtm. The sqrtm function chooses the positive square roots and produces Y1, even though Y2 seems to be a more natural result.

Y = sqrtm(A)
Y = 2×2

1.5667    1.7408
2.6112    4.1779

Input Arguments

collapse all

Input matrix, specified as a square matrix.

Data Types: single | double
Complex Number Support: Yes

Tips

• Some matrices, like A = [0 1; 0 0], do not have any square roots, real or complex, and sqrtm cannot be expected to produce one.

Algorithms

The algorithm sqrtm uses is described in .

 N.J. Higham, “Computing real square roots of a real matrix,” Linear Algebra and Appl., 88/89, pp. 405–430, 1987

 Bjorck, A. and S. Hammerling, “A Schur method for the square root of a matrix,” Linear Algebra and Appl., 52/53, pp. 127–140, 1983

 Deadman, E., Higham, N. J. and R. Ralha, “Blocked Schur algorithms for computing the matrix square root,” Lecture Notes in Comput. Sci., 7782, Springer-Verlag, pp. 171–182, 2013