# Subspaces Angle (G Dataflow)

Computes the angle between column spaces of two matrices.

## vector a

A real vector.

This input accepts a 1D array of double-precision, floating-point numbers or a 2D array of double-precision, floating-point numbers. If this input is a 1D array of double-precision, floating-point numbers, you must wire a 1D array of double-precision, floating point numbers to vector b. This input changes to matrix A when the data type is a 2D array of double-precision, floating-point numbers.

Default: Empty array

## vector b

A real vector.

This input accepts a 1D array of double-precision, floating-point numbers or a 2D array of double-precision, floating-point numbers. This input changes to matrix B when the data type is a 2D array of double-precision, floating-point numbers.

The length of vector a or the number of rows in matrix A must equal the length of vector b or the number of rows in matrix B. Otherwise, the node returns NaN as the output angle and returns an error.

## matrix A

A real matrix.

This input accepts a 1D array of double-precision, floating-point numbers or a 2D array of double-precision, floating-point numbers. This input changes to vector a when the data type is a 1D array of double-precision, floating-point numbers.

## matrix B

A real matrix.

This input accepts a 1D array of double-precision, floating-point numbers or a 2D array of double-precision, floating-point numbers. This input changes to vector b when the data type is a 1D array of double-precision, floating-point numbers.

The length of vector a or the number of rows in matrix A must equal the length of vector b or the number of rows in matrix B. Otherwise, the node returns NaN as the output angle and returns an error.

## error in

Error conditions that occur before this node runs. The node responds to this input according to standard error behavior.

Default: No error

## angle

Angle, in radians, between the column subspaces of the inputs.

## error out

Error information. The node produces this output according to standard error behavior.

## Algorithm for Calculating the Angle between Subspaces of Two Matrices or Two Vectors

Let U1S1V1T and U2S2V2T be the singular value decomposition of matrix A and matrix B, respectively. The following equation defines the angle between the Euclidean subspaces that span the columns of matrix A and matrix B.

$\text{angle}=\mathrm{arccos}\left(s\right)$

where s is the minimum singular value of U1TU2.

For inputs vector a and vector b, the previous equation equals the following equation.

$\text{angle}=\mathrm{arccos}\left(\frac{{a}^{T}b}{‖a‖‖b‖}\right)$

where a is the input vector a and b is the input vector b, and the norm symbols (||.||) compute the 2-norm of the input vectors.

Where This Node Can Run:

Desktop OS: Windows

FPGA: Not supported