Matrix square root
collapse all in page
Syntax
X = sqrtm(A)
[X,residual] = sqrtm(A)
[X,alpha,condx] = sqrtm(A)
Description
example
X = sqrtm(A)
returnsthe principal square root of the matrix A
, thatis, X*X = A
.
X
is the unique square root for which everyeigenvalue has nonnegative real part. If A
hasany eigenvalues with negative real parts, then a complex result isproduced. If A
is singular, then A
mightnot have a square root. If exact singularity is detected, a warningis printed.
[X,residual] = sqrtm(A)
alsoreturns 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)
returnsstability factor alpha
and an estimate of the matrixsquare root condition number of X
in 1-norm, condx
.The residual norm(A-X^2,1)/norm(A,1)
is boundedapproximately by n*alpha*eps
and the 1-norm relativeerror in X
is bounded approximately by n*alpha*condx*eps
,where n=max(size(A))
.
Examples
collapse all
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 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
Matrix with Multiple Square Roots
Open Live Script
Consider a matrix that has four square roots, A
.
Two of the square roots of A
are given by Y1
and Y2
:
Confirm that Y1
and Y2
are square roots of matrix A
.
A = [7 10; 15 22];Y1 = [1.5667 1.7408; 2.6112 4.1779];A - Y1*Y1
ans = 2×210-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 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 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 Y
:
Calculate the square root 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
A
— Input matrix
square matrix
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, andsqrtm
cannotbe expected to produce one.
Algorithms
The algorithm sqrtm
uses is described in [3].
References
[1] N.J. Higham, “Computing real squareroots of a real matrix,” Linear Algebra and Appl.,88/89, pp. 405–430, 1987
[2] Bjorck, A. and S. Hammerling, “ASchur method for the square root of a matrix,” LinearAlgebra and Appl., 52/53, pp. 127–140, 1983
[3] Deadman, E., Higham, N. J. and R. Ralha,“Blocked Schur algorithms for computing the matrix square root,” LectureNotes in Comput. Sci., 7782, Springer-Verlag, pp. 171–182,2013
Extended Capabilities
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
NaN
values.In the generated code, the output of
sqrtm
is always complex.Code generation does not support sparse matrix inputs for this function.
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version History
Introduced before R2006a
See Also
expm | funm | logm
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本 (日本語)
- 한국 (한국어)
Contact your local office