# Matrix Balance (G Dataflow)

Balances a general matrix to improve the accuracy of computed eigenvalues and eigenvectors.

##### Programming Patterns

Use the Back Transform Eigenvectors node after balancing a matrix with the Matrix Balance node and computing the eigenvectors of the balanced matrix with the Eigenvalues and Vectors node. Use the outputs of the Matrix Balance node and the Eigenvalues and Vectors node as the inputs of the Back Transform Eigenvectors node.  ## matrix

A real general matrix.

This input accepts a 2D array of double-precision, floating point numbers or 2D array of complex double-precision, floating point numbers. ## job

Type of matrix balance operation to perform.

Name Value Description
Neither Permuted nor Scaled 0 The node neither permutes nor scales the matrix.
Permuted but not Scaled 1 The node permutes but does not scale the matrix.
Scaled but not Permuted 2 The node scales but does not permute the matrix.
Both Permuted and Scaled 3 The node permutes and scales the matrix.

Default: Both Permuted and Scaled ## 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 ## balanced matrix

The balanced matrix containing the same eigenvalues as the input matrix. ## index low

The form of the balanced matrix.

If job is Neither Permuted nor Scaled or Scaled but not Permuted, this output equals 0.

Algorithm for Defining the Form of the Balanced Matrix

balanced matrix(i,j) = 0 if i > j and 0 ≤ j < index low. ## index high

The form of the balanced matrix.

If job is Neither Permuted nor Scaled or Scaled but not Permuted, this output equals n - 1.

Algorithm for Defining the Form of the Balanced Matrix

balanced matrix(i,j) = 0 if i > j and index high < in - 1. ## 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. ## scale

Details about the permutations and scaling factors.

Algorithm for Calculating scale

If pj is the index of the row and column interchanged with row and column j, and dj is the scaling factor used to balance row and column j, the following equations define how this node computes the values of this output.

$\begin{array}{cc}{\text{scale}}_{j}={p}_{j}& \text{for}j=0,1,...,{i}_{low}-1,{i}_{high}+1,...,n-1\end{array}$
$\begin{array}{cc}{\text{scale}}_{j}={d}_{j}& \text{for}j={i}_{low},{i}_{low}+1,...,{i}_{high}\end{array}$

where ilow is the output index low and ihigh is the output index high.

## Improving the Accuracy of Eigenvalues and Eigenvectors

You can use one or both of the following similarity transformations to balance a matrix A and improve the accuracy of computed eigenvalues and eigenvectors:

• Permute matrix A to block upper triangular form.
• Scale matrix A' to reduce the norm of matrix A'22.

## Permuting Matrix A

The following expression defines the permutation of matrix A to block upper triangular form.

${PAP}^{T}=A\prime =\left[\begin{array}{ccc}{A}_{11}^{\prime }& {A}_{12}^{\prime }& {A}_{13}^{\prime }\\ 0& {A}_{22}^{\prime }& {A}_{23}^{\prime }\\ 0& 0& {A}_{33}^{\prime }\end{array}\right]$

where

• P is a permutation matrix
• A'11 and A'33 are upper triangular
• PT is the transpose of matrix P

The diagonal elements of A'11 and A'33 are eigenvalues of A. The central diagonal block A'22 starts from column(row) input index low and ends in column(row) input index high of A'. If no suitable permutation of A exists, the following conditions are true:

• A'22 is the whole of A.
• index low = 0.
• index high = n - 1.

## Scaling Matrix A'

The following expression defines the scaling of matrix A' to reduce the norm of matrix A'22.

${A}^{\prime \prime }={D}^{-1}A\prime D=\left[\begin{array}{ccc}I& 0& 0\\ 0& {D}_{22}^{-1}& 0\\ 0& 0& I\end{array}\right]\left[\begin{array}{ccc}{A}_{11}^{\prime }& {A}_{12}^{\prime }& {A}_{13}^{\prime }\\ 0& {A}_{22}^{\prime }& {A}_{23}^{\prime }\\ 0& 0& {A}_{33}^{\prime }\end{array}\right]\left[\begin{array}{ccc}I& 0& 0\\ 0& {D}_{22}& 0\\ 0& 0& I\end{array}\right]=\left[\begin{array}{ccc}{A}_{11}^{\prime \prime }& {A}_{12}^{\prime \prime }& {A}_{13}^{\prime \prime }\\ 0& {A}_{22}^{\prime \prime }& {A}_{23}^{\prime \prime }\\ 0& 0& {A}_{33}^{\prime \prime }\end{array}\right]$

so that ||A"22|| < ||A'22||, which reduces the effect of rounding errors on the accuracy of computed eigenvalues and eigenvectors.

Where This Node Can Run:

Desktop OS: Windows

FPGA: Not supported

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