# Subspaces Angle (G Dataflow)

Version:
Last Modified: January 12, 2018

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.

Standard Error Behavior

Many nodes provide an error in input and an error out output so that the node can respond to and communicate errors that occur while code is running. The value of error in specifies whether an error occurred before the node runs. Most nodes respond to values of error in in a standard, predictable way.

error in does not contain an error error in contains an error
If no error occurred before the node runs, the node begins execution normally.

If no error occurs while the node runs, it returns no error. If an error does occur while the node runs, it returns that error information as error out.

If an error occurred before the node runs, the node does not execute. Instead, it returns the error in value as error out.

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.

Standard Error Behavior

Many nodes provide an error in input and an error out output so that the node can respond to and communicate errors that occur while code is running. The value of error in specifies whether an error occurred before the node runs. Most nodes respond to values of error in in a standard, predictable way.

error in does not contain an error error in contains an error
If no error occurred before the node runs, the node begins execution normally.

If no error occurs while the node runs, it returns no error. If an error does occur while the node runs, it returns that error information as error out.

If an error occurred before the node runs, the node does not execute. Instead, it returns the error in value as error out.

## 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

Web Server: Not supported in VIs that run in a web application