Main Content

sqrtm

Matrix square root

Description

X = sqrtm(A) returns a matrix X, such that X2 = A and the eigenvalues of X are the square roots of the eigenvalues of A.

example

[X,resnorm] = sqrtm(A) returns a matrix X and the residual norm(A-X^2,'fro')/norm(A,'fro').

example

Examples

Compute Square Root of Matrix

Compute the square root of this matrix. Because these numbers are not symbolic objects, you get floating-point results.

A = [2 -2 0; -1 3 0; -1/3 5/3 2];
X = sqrtm(A)
X =
    1.3333   -0.6667    0.0000
   -0.3333    1.6667   -0.0000
   -0.0572    0.5286    1.4142

Now, convert this matrix to a symbolic object, and compute its square root again:

A = sym([2 -2 0; -1 3 0; -1/3 5/3 2]);
X = sqrtm(A)
X =
[               4/3,          -2/3,       0]
[              -1/3,           5/3,       0]
[ (2*2^(1/2))/3 - 1, 1 - 2^(1/2)/3, 2^(1/2)]

Check the correctness of the result:

isAlways(X^2 == A)
ans =
  3×3 logical array
   1   1   1
   1   1   1
   1   1   1

Return Residual of Matrix Square Root

Use the syntax with two output arguments to return the square root of a matrix and the residual:

A = vpa(sym([0 0; 0 5/3]), 100);
[X,resnorm] = sqrtm(A)
X =
[ 0,                                 0]
[ 0, 1.2909944487358056283930884665941]
 
resnorm =
2.9387358770557187699218413430556e-40

Input Arguments

collapse all

Input, specified as a symbolic matrix.

Output Arguments

collapse all

Matrix square root, returned as a symbolic matrix such that X2 = A.

Residual, returned as a symbolic expression. The residual is computed as norm(A-X^2,'fro')/norm(A,'fro').

Tips

  • Calling sqrtm for a matrix that is not a symbolic object invokes the MATLAB® sqrtm function.

Version History

Introduced in R2013a

See Also

| | | | | |