Function Repository Resource:

SubspaceAngle

Source Notebook

Compute the angle between two subspaces

Contributed by: Jan Mangaldan

ResourceFunction["SubspaceAngle"][u,v]

gives the angle between two subspaces specified by the columns of the matrices u and v.

Details and Options

The matrices u and v must be numerical matrices with the same number of rows.
Vectors are treated as column matrices.
If the elements of u or v are exact numbers, ResourceFunction["SubspaceAngle"] begins by applying N to them.
ResourceFunction["SubspaceAngle"] gives an angle in radians.

Examples

Basic Examples (1) 

Compute the angle between two subspaces:

In[1]:=
a = {{1., 1.}, {1., 2.}, {1., 3.}};
b = {{7., 3.}, {1., 1.}, {5., -8.}};
ResourceFunction["SubspaceAngle"][a, b]
Out[3]=

Scope (2) 

Find the subspace angle between a vector and a matrix:

In[4]:=
ResourceFunction["SubspaceAngle"][{1., 2., 3.}, ( {
   {1., 2.},
   {1., 3.},
   {1., 5.}
  } )]
Out[4]=

Find the subspace angle between different sets of columns of a complex matrix:

In[5]:=
fm = FourierMatrix[8, FourierParameters -> {1, -1}, WorkingPrecision -> 20];
In[6]:=
ResourceFunction["SubspaceAngle"][fm[[All, 1 ;; 3]], fm[[All, 5 ;; 8]]]
Out[6]=

Properties and Relations (2) 

For two vectors, SubspaceAngle gives the same result as VectorAngle:

In[7]:=
ResourceFunction["SubspaceAngle"][{1., 2., 3.}, {1., 1., 1.}]
Out[7]=
In[8]:=
VectorAngle[{1., 2., 3.}, {1., 1., 1.}]
Out[8]=

Use SubspaceAngle to compute the angle between two planes by specifying the vectors spanning each plane as matrix columns:

In[9]:=
ResourceFunction["SubspaceAngle"][( {
   {0., 1.},
   {1., 0.},
   {0., 1.}
  } ), ( {
   {0., 1.},
   {1., 0.},
   {0., 0.}
  } )]
Out[9]=

Use DihedralAngle to compute the same result:

In[10]:=
DihedralAngle[{{0., 0., 0.}, {0., 1., 0.}}, {{1., 0., 1.}, {1., 0., 0.}}]
Out[10]=

Version History

  • 1.0.0 – 08 February 2023

Source Metadata

Related Resources

License Information