Matrix square root
X = sqrtm( returns
the principal square root of the matrix
X*X = A.
X is the unique square root for which every
eigenvalue has nonnegative real part. If
any eigenvalues with negative real parts, then a complex result is
A is singular, then
not have a square root. If exact singularity is detected, a warning
[X,residual] = sqrtm( 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( returns
alpha and an estimate of the matrix
square root condition number of
X in 1-norm,
norm(A-X^2,1)/norm(A,1) is bounded
n*alpha*eps and the 1-norm relative
X is bounded approximately by
n = max(size(A)).
Matrix Square Root of Difference Operator
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
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
Matrix with Multiple Square Roots
Consider a matrix that has four square roots,
Two of the square roots of
A are given by
Y2 are square roots of matrix
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 square roots of
-Y2. All four of these roots can be obtained from the eigenvalues and eigenvectors of
[V,D] = eig(A), then the square roots 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
Calculate the square root of
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
A — Input matrix
Input matrix, specified as a square matrix.
Complex Number Support: Yes
Some matrices, like
A = [0 1; 0 0], do not have any square roots, real or complex, and
sqrtmcannot be expected to produce one.
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
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
When the input matrix contains a nonfinite value, the generated code does not issue an error. Instead, the output contains
In the generated code, the output of
sqrtmis always complex.
Code generation does not support sparse matrix inputs for this function.
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Introduced before R2006a