# sqrtm

## Purpose

Matrix square root.

## Synopsis

    Y = sqrtm(X)

## Description

`Y = sqrtm(X)` is one of the many matrices that satisfy

    Y*Y = X

If `X` is symmetric and positive definite, then `Y` is the unique positive definite square root.

## Examples

A matrix representation of the fourth difference operator is

    X =
         5   -4    1    0    0
        -4    6   -4    1    0
         1   -4    6   -4    1
         0    1   -4    6   -4
         0    0    1   -4    5

This matrix is symmetric and positive definite. Its unique positive definite square root, `Y = sqrtm(X)`, is a representation of the second difference operator.

     Y =
         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

The matrix

    X =
         7   10
        15   22

has four square roots. Two of them are

    Y1 =
        1.5667    1.7408
        2.6112    4.1779

and

    Y2 =
         1    2
         3    4

The other two are `-Y1` and `-Y2`. All four can be obtained from the eigenvalues and vectors of `X`.

    [V,D] = eig(X);

    D =
        0.1386          0
             0    28.8614

The four square roots of the diagonal matrix `D` result from the four choices of sign in

    S =
        ±0.3723          0
              0    ±5.3723

All four `Y`s are of the form

    Y = V*S/V

The `sqrtm` function chooses the two plus signs and produces `Y1`, even though `Y2` is more natural because its entries are integers.

Finally, the matrix

     X =
         0    1
         0    0

does not have any square roots. There is no matrix `Y`, real or complex, for which `Y`*`Y = X`. The statement

    Y = sqrtm(X)

produces

    WARNING: Result from FUNM is probably inaccurate.

    Y =
         0    0
         0    0

## Algorithm

The function `sqrtm(X)` is an abbreviation for `funm(X,'sqrt')`. The algorithm used by `funm` is based on a Schur decomposition. It can fail in certain situations where `X` has repeated eigenvalues. See `funm` for details.

## See Also

    expm, funm, logm

(c) Copyright 1994 by The MathWorks, Inc.