Function Repository Resource:

MatrixSign

Source Notebook

Evaluate the matrix sign function

Contributed by: Jan Mangaldan

ResourceFunction["MatrixSign"][m]

gives the matrix sign of m.

ResourceFunction["MatrixSign"][m,v]

gives the matrix sign of m applied to the vector v.

Details

The matrix sign function was introduced by Roberts in 1971 as a tool for model reduction and for solving Lyapunov and algebraic Riccati equations.
The matrix sign function sgn is defined by sgn(m)=m·(m2)-1/2, where mp is MatrixPower[m,p].
ResourceFunction["MatrixSign"] works only on square matrices.
In ResourceFunction["MatrixSign"][m,v] the matrix m can be a SparseArray object.

Examples

Basic Examples (2) 

Sign of a 2×2 matrix:

In[1]:=
ResourceFunction["MatrixSign"][{{1.2, 5.6}, {3, 4}}]
Out[1]=

Sign applied to a vector:

In[2]:=
ResourceFunction["MatrixSign"][{{1.2, 5.6}, {3, 4}}, {1, 2}]
Out[2]=

Scope (7) 

Find the matrix sign of a MachinePrecision matrix:

In[3]:=
ResourceFunction[
 "MatrixSign"][{{1.25, 3, 2}, {7.9, -1.4, 2}, {3.2, 2.7, 6.5}}]
Out[3]=

Matrix sign of a complex matrix:

In[4]:=
ResourceFunction[
  "MatrixSign"][{{1. + I, 2, 3 - 2 I}, {0, 4 \[Pi], 5 I}, {E, 0, 6}}] // MatrixForm
Out[4]=

Matrix sign of an exact matrix:

In[5]:=
ResourceFunction["MatrixSign"][{{3, 1, 1}, {1, 0, 1}, {1, 2, 1}}]
Out[5]=

Matrix sign of an arbitrary-precision matrix:

In[6]:=
ResourceFunction["MatrixSign"][
 RandomReal[{-1, 1}, {2, 2}, WorkingPrecision -> 20]]
Out[6]=

Matrix sign of a symbolic matrix:

In[7]:=
ResourceFunction["MatrixSign"][{{a, b}, {0, c}}]
Out[7]=

Computing the sign of large machine-precision matrices is efficient:

In[8]:=
m = RandomReal[{0, 1}, {800, 800}];
ResourceFunction["MatrixSign"][m]; // AbsoluteTiming
Out[8]=

Directly applying the sign to a single vector is more efficient:

In[9]:=
ResourceFunction["MatrixSign"][m, Range[800]]; // AbsoluteTiming
Out[9]=

Directly apply the matrix sign of a sparse matrix to a sparse vector:

In[10]:=
m = SparseArray[{Band[{2, 1}] -> 2, Band[{1, 2}] -> 2}, {1000, 1000}];
v = SparseArray[{{1} -> 1, {-1} -> -1.5}, {1000}];
ResourceFunction["MatrixSign"][m, v] // Short
Out[10]=

Properties and Relations (5) 

The matrix sign is involutory:

In[11]:=
m = RandomReal[1, {5, 5}];
MatrixPower[ResourceFunction["MatrixSign"][m], 2] // Chop
Out[11]=

If m is invertible, its matrix sign has eigenvalues of ±1:

In[12]:=
sgn = ResourceFunction["MatrixSign"][{{1.2, 5.6}, {3, 4}}];
Eigenvalues[%]
Out[13]=

The matrix sign of a diagonal matrix is diagonal:

In[14]:=
d = {1, 2, 3, 4};
ResourceFunction["MatrixSign"][DiagonalMatrix[d t]]
Out[14]=

If m is invertible, then sgn(m) is unimodular (has Det(sgn(m))=±1):

In[15]:=
m = RandomComplex[{-1 - I, 1 + I}, {3, 3}]
Out[15]=
In[16]:=
Det[ResourceFunction["MatrixSign"][m]] // Chop
Out[16]=

If m is diagonalizable with m=v-1.d.v, then sgn(m)=v-1.sgn(Re(d)).v:

In[17]:=
m = RandomReal[1, {3, 3}];
{d, vt} = Eigensystem[m]
Out[17]=
In[18]:=
v = Transpose[vt];
v . DiagonalMatrix[Sign[Re[d]]] . Inverse[v] - ResourceFunction["MatrixSign"][m] // Chop
Out[18]=

Neat Examples (1) 

Verify an identity involving the matrix sign and the matrix square root:

In[19]:=
With[{a = RandomReal[{-1, 1}, {3, 3}, WorkingPrecision -> 25], b = RandomReal[{-1, 1}, {3, 3}, WorkingPrecision -> 25]},
 ResourceFunction["MatrixSign"][ArrayFlatten[( {
      {0, a},
      {b, 0}
     } )]] == With[{c = a . MatrixPower[b . a, -1/2]}, ArrayFlatten[( {
      {0, c},
      {Inverse[c], 0}
     } )]]]
Out[19]=

Version History

  • 1.0.0 – 23 March 2021

Source Metadata

Related Resources

License Information