subspace

Angle between two subspaces, given by the columns of two matrices.

Category: Mathematics > Linear Algebra

Syntax

theta = subspace(A, B)

Returns the largest principal angle between range(A) and range(B), in radians.

Description

For two vectors the result is the ordinary angle between them, ignoring orientation, so it never exceeds pi/2. For larger subspaces it is the largest of the principal angles, which measures how far the subspaces are from containing one another.

The angle is 0 when one subspace is contained in the other and has the smaller dimension, and pi/2 when the subspaces are orthogonal.

Input arguments

A, B
Matrices with the same number of rows. Their columns span the two subspaces.

Output arguments

theta
Scalar angle between 0 and pi/2.

Example

Angles between lines

subspace([1; 0], [1; 1])
subspace([1; 0], [0; 1])
pi/4
Output
ans = 0.7854
ans = 1.5708
ans = 0.7854

See also

orth null svd dot rank