Singular value decomposition (SVD) of a 2×2 matrix

The following details how to compute the singular value decomposition (SVD) of a 2x2 matrix. For reminder :

$$ A=\left[ \begin{matrix} a & b \\ c & d \end{matrix} \right]=U \cdot \Sigma \cdot V^T $$

where \(U\) and \(V\) are orthogonal and \(\Sigma\) is a diagonal matrix containing the singular values. In the particular case of a 2x2 matrix, the decomposition is given by:

$$ A= \left[ \begin{matrix} cos(\theta) & -sin(\theta) \\ sin(\theta) & cos(\theta) \end{matrix} \right] \cdot \left[ \begin{matrix} \sigma_1 & 0 \\ 0 & \sigma_2 \end{matrix} \right] \cdot \left[ \begin{matrix} cos(\phi) & -sin(\phi) \\ sin(\phi) & cos(\phi) \end{matrix} \right] $$

With:

$$ \begin{matrix} V=C \cdot W=\left[ \begin{matrix} \pm{1} & 0 \\ 0 & \pm{1} \end{matrix} \right] \end{matrix} $$

Computation of \(U\)

\( \theta \) is given by: $$ \theta=\frac{1}{2} atan2 (2ac+2bd , a^2+b^2-c^2-d^2) $$

The matrix \(U\) is given by: $$ U=\left[ \begin{matrix} cos(\theta) & -sin(\theta) \\ sin(\theta) & cos(\theta) \end{matrix} \right] $$

Computation of \( \Sigma \)

The singular values are given by:

$$ \begin{matrix} \sigma_1 &=& \sqrt{ \frac {S_1 + S_2}{2} } \\ \sigma_2 &=& \sqrt{ \frac {S_1 - S_2}{2} } \\ \end{matrix} $$

With:

$$ \begin{matrix} S_1 &=& a^2+b^2+c^2+d^2 \\ S_2 &=& \sqrt{(a^2+b^2-c^2-d^2)^2 + 4(ac+bd)^2 } \end{matrix} $$

The matrix \( \Sigma \) is given by: $$ \Sigma=\left[ \begin{matrix} \sigma_1 & 0 \\ 0 & \sigma_2 \end{matrix} \right] $$

Computation of \( V \)

First, let's compute the temporary angle \( \Phi \) with the following formula:

$$ \Phi=\frac{1}{2} atan2 (2ab+2cd , a^2-b^2+c^2-d^2) $$

Let's now compute the following scalars:

$$ \begin{matrix} s_{11} &=& (a.c_\theta+c.s_\theta).c_\Phi &+& (b.c_\theta+d.s_\theta).s_\Phi \\ s_{22} &=& (a.s_\theta-c.c_\theta).s_\Phi &+& (-b.s_\theta+d.c_\theta).c_\Phi \\ \end{matrix} $$

where:

$$ \begin{matrix} c_\Phi=cos(\Phi) \\ s_\Phi=sin(\Phi) \\ c_\theta=cos(\theta) \\ s_\theta=sin(\theta) \end{matrix} $$

The matrix \(V\) is given by:

$$ V=\left[ \begin{matrix} \frac {s_{11}} {|s_{11}|}cos(\Phi) & -\frac {s_{22}} {|s_{22}|}sin(\Phi) \\ \frac {s_{11}} {|s_{11}|} sin(\Phi) & \frac {s_{22}} {|s_{22}|}cos(\Phi) \end{matrix} \right] $$

Note that \( \frac {s_{11}} {|s_{11}|} \) and \( \frac {s_{22}} {|s_{22}|} \) are respectively the sign of \( s_{11}\) and \(s_{22}\). If \(s_{11}\) or \(s_{22}\) are 0, dividing them by their absolute value will fail in most programming languages. The Matlab sign function returns 0 in this case.

Matlab function

%% Matlab function for computing the SVD of a 2x2 matrix
%% Written by Randy Ellis
%% More information at: http://www.lucidar.me

function [U,SIG,V] = svd2x2(A)
% [U,SIG,V] = svd2x2(A) finds the SVD of 2x2 matrix A
% where U and V are orthogonal, SIG is diagonal,
% and A=U*SIG*V’
% Find U such that U*A*A’*U’=diag
Su = A*A';
phi = 0.5*atan2(Su(1,2)+Su(2,1), Su(1,1)-Su(2,2));
Cphi = cos(phi);
Sphi = sin(phi);
U = [Cphi -Sphi ; Sphi Cphi];

% Find W such that W’*A’*A*W=diag
Sw = A'*A;
theta = 0.5*atan2(Sw(1,2)+Sw(2,1), Sw(1,1)-Sw(2,2));
Ctheta = cos(theta);
Stheta = sin(theta);
W = [Ctheta, -Stheta ; Stheta, Ctheta];

% Find the singular values from U
SUsum= Su(1,1)+Su(2,2);
SUdif= sqrt((Su(1,1)-Su(2,2))^2 + 4*Su(1,2)*Su(2,1));
svals= [sqrt((SUsum+SUdif)/2) sqrt((SUsum-SUdif)/2)];
SIG =diag(svals);

% Find the correction matrix for the right side
S = U'*A*W
C = diag([sign(S(1,1)) sign(S(2,2))]);
V = W*C;

Download

Example script for Matlab can be downloaded below:

svd_2x2.zip

Credits: based on the report of Randy Ellis : Singular Value Decomposition of a 2x2 Matrix.

See also


Last update : 06/11/2018