%% Matrix with Multiple Squareroots
% Consider a matrix that has four squareroots, A.
% A = \left[ \matrix{7 & 10 \cr 15 & 22} \right]
% Two of the squareroots of A are given by Y1 and Y2:
% Y_1 = \left[ \matrix{1.5667 & 1.7408 \cr 2.6112 & 4.1779} \right]
% Y_2 = \left[ \matrix{1 & 2 \cr 3 & 4} \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

%

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

%
% 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[ \matrix{\pm 0.3723 & 0 \cr 0 & \pm 5.3723} \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)

% Copyright 2015 The MathWorks, Inc.