Search

Search papers and lessons

Matrix Square Root

Level 2 · 11 min read

A matrix square root is a matrix that gives the original matrix when multiplied by itself; a symmetric matrix with positive eigenvalues always has exactly one special square root.

On this page

  • Colour = topic mix
  • Linear algebra
  • Discrete math
  • ReadReady to readNot yet

TL;DR

A square root of a matrix AA is a matrix SS such that SS times SS equals AA, just as 3 is a square root of 9 because 3×3=93 \times 3 = 9. When AA is a symmetric matrix whose eigenvalues are all positive, there is exactly one square root that is also symmetric with positive eigenvalues. You build it by taking the ordinary square root of each eigenvalue. It matters when a problem is stated in matrix form and needs a "half step" of a matrix, such as shaping random noise to match a covariance matrix or comparing two clouds of data.

Builds on: Symmetric Matrix, Positive Definite Matrix, Eigenvalues and Eigenvectors, Matrix Multiplication · Leads to: Fréchet Inception Distance

Where it's used

Judging image generators. The Fréchet Inception Distance (FID) scores generated pictures by comparing the mean and covariance of network features computed on real images and on generated ones. Its formula contains the square root of a product of two covariance matrices. Each one is a square table with 2048 rows and columns, estimated from tens of thousands of images. Every FID score depends on this matrix square root.

Generating correlated random numbers. To make a random vector xx with covariance Σ\Sigma, you multiply a matrix SS with SS=ΣS S = \Sigma by a vector of independent standard normal numbers. Simulators in finance and physics use this to create correlated shocks. Cholesky decomposition does the same job more cheaply, so the symmetric square root is chosen only when the symmetry itself matters.

Comparing quantum states. The fidelity between two quantum states is defined using square roots of their density matrices, which are symmetric positive matrices. Physicists compute these roots to measure how easily one state can be told apart from another.

How it works

Take the symmetric matrix

A=(5445).A = \begin{pmatrix} 5 & 4 \\ 4 & 5 \end{pmatrix}.

We want a matrix SS with SS=AS S = A.

  1. Check the conditions. The entry in row 1, column 2 is 4, and the entry in row 2, column 1 is also 4. Swapping rows and columns leaves AA unchanged, so AA is symmetric. Check: the matrix has no hidden asymmetry.

  2. Find the eigenvalues, the stretch factors λ\lambda for which Av=λvA v = \lambda v has a nonzero solution vv. The eigenvalues add up to the trace 5+5=105 + 5 = 10 and multiply to the determinant 25−16=925 - 16 = 9. The pair that does both is 9 and 1. Check: 9+1=109 + 1 = 10 and 9×1=99 \times 1 = 9.

  3. Find an eigenvector for each eigenvalue. For λ=9\lambda = 9, the vector (1,1)(1, 1) works, because A(1,1)=(9,9)A (1, 1) = (9, 9). For λ=1\lambda = 1, the vector (1,−1)(1, -1) works, because A(1,−1)=(1,−1)A (1, -1) = (1, -1).

  4. Scale each eigenvector to length 1. Both have length 2\sqrt{2}, so the unit vectors are q1=(1,1)/2q_1 = (1,1)/\sqrt{2} and q2=(1,−1)/2q_2 = (1,-1)/\sqrt{2}. They are at right angles, so placed side by side as columns they form an orthogonal matrix QQ. Check: the dot product of q1q_1 and q2q_2 is (1−1)/2=0(1 - 1)/2 = 0.

  5. Take the ordinary square root of each eigenvalue: 9=3\sqrt{9} = 3 and 1=1\sqrt{1} = 1. Put them on the diagonal of a diagonal matrix, Λ1/2=diag⁡(3,1)\Lambda^{1/2} = \operatorname{diag}(3, 1). Check: squaring each diagonal entry gives back 9 and 1.

  6. Rebuild the matrix from these pieces: S=Q Λ1/2 QTS = Q \, \Lambda^{1/2} \, Q^{\mathsf T}. Multiplying out gives

    S=(2112).S = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}.

    Check: each diagonal entry is the average of the two roots, (3+1)/2=2(3 + 1)/2 = 2.

  7. Square SS to confirm. The (1,1) entry is 2⋅2+1⋅1=52 \cdot 2 + 1 \cdot 1 = 5 and the (1,2) entry is 2⋅1+1⋅2=42 \cdot 1 + 1 \cdot 2 = 4. Both match AA.

The steps form a pipeline. The matrix only stretches along a few perpendicular directions, and the square root takes the root of each stretch while keeping the directions the same.

flowchart LR
  A["A: symmetric, positive eigenvalues"] --> E["eigenvalues and unit eigenvectors"]
  E --> R["square root of each eigenvalue"]
  R --> S["S = Q times sqrt(Lambda) times Q-transpose"]

The math

Let AA be a symmetric matrix whose eigenvalues λ1,…,λn\lambda_1, \dots, \lambda_n are all positive, such a matrix is called positive definite. Its principal square root is the unique symmetric matrix SS with all positive eigenvalues and SS=AS S = A.

Step 4 in symbols: the spectral decomposition

Because AA is symmetric, its eigenvectors can be chosen at right angles and scaled to length 1. Stacking them as the columns of QQ gives

A=QΛQT,Λ=diag⁡(λ1,…,λn).A = Q \Lambda Q^{\mathsf T}, \qquad \Lambda = \operatorname{diag}(\lambda_1, \dots, \lambda_n).

Here QTQ^{\mathsf T} is the transpose of QQ, the matrix with rows and columns swapped. Check with the example: with Λ=diag⁡(9,1)\Lambda = \operatorname{diag}(9, 1), the product QΛQTQ \Lambda Q^{\mathsf T} gives back AA.

Step 5 in symbols: the square root

Define

Λ1/2=diag⁡(λ1,…,λn),S=QΛ1/2QT.\Lambda^{1/2} = \operatorname{diag}\bigl(\sqrt{\lambda_1}, \dots, \sqrt{\lambda_n}\bigr), \qquad S = Q \Lambda^{1/2} Q^{\mathsf T}.

Then

SS=QΛ1/2QTQ⏟=IΛ1/2QT=Q Λ1/2Λ1/2 QT=QΛQT=A.S S = Q \Lambda^{1/2} \underbrace{Q^{\mathsf T} Q}_{= I} \Lambda^{1/2} Q^{\mathsf T} = Q \, \Lambda^{1/2} \Lambda^{1/2} \, Q^{\mathsf T} = Q \Lambda Q^{\mathsf T} = A.

The middle pair QTQQ^{\mathsf T} Q equals the identity matrix II because the columns of QQ are unit vectors at right angles. Then Λ1/2Λ1/2=Λ\Lambda^{1/2} \Lambda^{1/2} = \Lambda, since each diagonal entry is λi×λi=λi\sqrt{\lambda_i} \times \sqrt{\lambda_i} = \lambda_i.

For one number, this is the usual square root. The plot shows y=xy = \sqrt{x} at the eigenvalues 1, 4 and 9.

02468100123eigenvalue lambdaroot sqrt(lambda)
  • square root
Along each eigenvector the matrix acts as a single number lambda, and the root acts on that number.

Worked examples

Example
1. A diagonal matrix (tiny)

Let A=(4009)A = \begin{pmatrix} 4 & 0 \\ 0 & 9 \end{pmatrix}.

  1. AA is already diagonal, so its eigenvectors are the coordinate axes (1,0)(1, 0) and (0,1)(0, 1), and Q=IQ = I.
  2. The eigenvalues are the diagonal entries, 4 and 9.
  3. Their square roots are 2 and 3.
  4. So S=(2003)S = \begin{pmatrix} 2 & 0 \\ 0 & 3 \end{pmatrix}.
  5. Check: SS=(4009)=AS S = \begin{pmatrix} 4 & 0 \\ 0 & 9 \end{pmatrix} = A.

Interpretation: when a matrix only stretches along the axes, its square root takes the root of each stretch.

Example
2. A symmetric matrix with mixed directions (standard)

Let A=(2112)A = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}.

  1. AA is symmetric, since the off-diagonal entries are both 1.
  2. The trace is 4 and the determinant is 4−1=34 - 1 = 3. The eigenvalues are 3 and 1, because 3+1=43 + 1 = 4 and 3×1=33 \times 1 = 3.
  3. Eigenvectors: A(1,1)=(3,3)A (1, 1) = (3, 3), so (1,1)(1, 1) belongs to 3. And A(1,−1)=(1,−1)A (1, -1) = (1, -1), so (1,−1)(1, -1) belongs to 1.
  4. Unit eigenvectors give Q=12(111−1)Q = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}.
  5. The roots of the eigenvalues are 3≈1.732\sqrt{3} \approx 1.732 and 1.
  6. Then S=Qdiag⁡(3,1)QT=12(3+13−13−13+1)≈(1.3660.3660.3661.366)S = Q \operatorname{diag}(\sqrt{3}, 1) Q^{\mathsf T} = \frac{1}{2} \begin{pmatrix} \sqrt{3} + 1 & \sqrt{3} - 1 \\ \sqrt{3} - 1 & \sqrt{3} + 1 \end{pmatrix} \approx \begin{pmatrix} 1.366 & 0.366 \\ 0.366 & 1.366 \end{pmatrix}.
  7. Check: the (1,1) entry of SSS S is 1.3662+0.3662=1.866+0.134=2.0001.366^2 + 0.366^2 = 1.866 + 0.134 = 2.000, and the (1,2) entry is 2×1.366×0.366=1.0002 \times 1.366 \times 0.366 = 1.000. Both match AA.

Interpretation: the root mixes the two coordinate directions in the same way the original matrix does. It is not the matrix of square roots of the entries, which we check in the common mistakes section.

Example
3. Shaping correlated noise (realistic)

Let the covariance be Σ=(5222)\Sigma = \begin{pmatrix} 5 & 2 \\ 2 & 2 \end{pmatrix}. We want SS with SS=ΣS S = \Sigma, so that x=Szx = S z has covariance Σ\Sigma when zz has independent standard normal entries.

  1. Σ\Sigma is symmetric. Its trace is 7 and its determinant is 10−4=610 - 4 = 6, so the eigenvalues are 6 and 1, since 6+1=76 + 1 = 7 and 6×1=66 \times 1 = 6.
  2. For 6, the eigenvector (2,1)(2, 1) works: Σ(2,1)=(12,6)=6(2,1)\Sigma (2, 1) = (12, 6) = 6 (2, 1). For 1, the eigenvector (1,−2)(1, -2) works: Σ(1,−2)=(1,−2)\Sigma (1, -2) = (1, -2). Scaling to unit length gives (2,1)/5(2,1)/\sqrt{5} and (1,−2)/5(1,-2)/\sqrt{5}.
  3. The roots of the eigenvalues are 6≈2.449\sqrt{6} \approx 2.449 and 1.
  4. Combine the two rank-one pieces: S=6 15(4221)+15(1−2−24)=15(46+126−226−26+4)S = \sqrt{6}\,\frac{1}{5}\begin{pmatrix} 4 & 2 \\ 2 & 1 \end{pmatrix} + \frac{1}{5}\begin{pmatrix} 1 & -2 \\ -2 & 4 \end{pmatrix} = \frac{1}{5}\begin{pmatrix} 4\sqrt{6} + 1 & 2\sqrt{6} - 2 \\ 2\sqrt{6} - 2 & \sqrt{6} + 4 \end{pmatrix}.
  5. Numerically, S≈(2.1600.5800.5801.290)S \approx \begin{pmatrix} 2.160 & 0.580 \\ 0.580 & 1.290 \end{pmatrix}.
  6. Check the first variance: the (1,1) entry of SSS S is 2.1602+0.5802=4.666+0.336=5.0022.160^2 + 0.580^2 = 4.666 + 0.336 = 5.002, which rounds to the 5 in Σ\Sigma.

Interpretation: multiplying independent noise by SS produces a pair whose first coordinate has variance 5, second has variance 2, and whose coordinates are correlated.

Try it: using the same SS, the (2,2) entry of SSS S should equal the (2,2) entry of Σ\Sigma. Compute 0.5802+1.29020.580^2 + 1.290^2. Answer: 0.336+1.664=2.0000.336 + 1.664 = 2.000, which matches the 2 in Σ\Sigma.

Common mistakes and tradeoffs

It is tempting to think the square root of a matrix is the matrix of square roots of its entries. In fact it is not, because multiplying matrices mixes entries together. The entrywise root of (2112)\begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix} is (2112)\begin{pmatrix} \sqrt{2} & 1 \\ 1 & \sqrt{2} \end{pmatrix}, and squaring it gives (322223)\begin{pmatrix} 3 & 2\sqrt{2} \\ 2\sqrt{2} & 3 \end{pmatrix}, not the original matrix.

It is tempting to think a matrix has only one square root. In fact the identity matrix has many, including II and −I-I and diag⁡(1,−1)\operatorname{diag}(1, -1). The symmetric root with positive eigenvalues is unique, and that is what "principal" means.

It is tempting to think every matrix has a square root. In fact N=(0100)N = \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix} has none. If BB=NB B = N, then B4=N2=0B^4 = N^2 = 0, so BB is nilpotent. A nilpotent 2×22 \times 2 matrix squares to zero, so BB=0B B = 0, which contradicts BB=N≠0B B = N \neq 0.

Use the symmetric square root when the symmetry matters, for example when the same covariance must be matched in any rotated coordinate system. Use Cholesky decomposition when you only need some matrix LL with LLT=ΣL L^{\mathsf T} = \Sigma, such as to generate samples. It is cheaper and produces a triangular matrix, which is easy to work with. For a matrix that is not symmetric or not square, the singular value decomposition is the right tool instead.

History

Matrix roots were studied soon after matrices themselves. Arthur Cayley's 1858 memoir on matrices discussed square roots, especially for 2×22 \times 2 matrices. The eigenvalue methods used here were developed over the nineteenth century, when people studied quadratic forms. For large matrices, computing a square root directly was impractical until computers made numerical methods possible. The Schur-based method of Björck and Hammarling, published in 1983, became a standard general algorithm. The idea reached machine learning in 2017, when the Fréchet Inception Distance used the matrix square root to compare image-feature distributions.

Recap

  • A square root SS of AA satisfies SS=AS S = A.
  • For a symmetric matrix with positive eigenvalues, the principal square root is unique.
  • The recipe: find the eigenvalues and orthonormal eigenvectors, take the square root of each eigenvalue, and rebuild S=QΛ1/2QTS = Q \Lambda^{1/2} Q^{\mathsf T}.
  • The root is what makes correlated noise with a given covariance possible.
  • Read next: the Fréchet Inception Distance, which uses the square root of a product of covariance matrices.

Check yourself

QuestionWhat does it mean for a matrix BB to be a square root of AA?Show answer

It means BB=AB B = A. Multiplying BB by itself, using matrix multiplication, returns AA.

QuestionFor A=(5445)A = \begin{pmatrix} 5 & 4 \\ 4 & 5 \end{pmatrix}, the principal square root is S=(2112)S = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}. What is the (1,2) entry of SS?Show answer

It is 1. The (1,2) entry of SSS S is 2×1+1×2=42 \times 1 + 1 \times 2 = 4, which is the (1,2) entry of AA, so the root is correct.

QuestionWhy is the matrix of entrywise square roots not the square root of (2112)\begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}?Show answer

Matrix squaring combines entries across rows and columns; it does not square each entry separately. Squaring the entrywise root gives (322223)\begin{pmatrix} 3 & 2\sqrt{2} \\ 2\sqrt{2} & 3 \end{pmatrix}, which is not the original matrix. The square root must be built from eigenvalues and eigenvectors.

QuestionA colleague says the Cholesky factor LL and the symmetric square root SS both produce samples with covariance Σ\Sigma. Is this right, and which is cheaper?Show answer

Yes. If zz has independent standard normal entries, then LzL z has covariance LLT=ΣL L^{\mathsf T} = \Sigma, and SzS z has covariance SS=ΣS S = \Sigma. Cholesky is cheaper, because it is computed directly from the entries of Σ\Sigma without finding eigenvalues, and LL is triangular.

Sources