# QR Decomposition (G Dataflow)

Performs the QR decomposition of a matrix with the option of column pivoting.  ## matrix A

An m-by-n matrix, where m is the number of rows in the matrix and n is the number of columns in the matrix.

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

The matrix can be either a square or rectangular matrix. ## pivot?

A Boolean that specifies whether the node uses column pivoting to decompose the input matrix.

 True Uses column pivoting. The following equation decomposes the matrix A: AP = QR. The node returns the absolute values of the diagonals of matrix R in descending order. False Does not use column pivoting. The following equation decomposes the matrix A: A = QR.

Default: False ## Q option

A value that specifies how the node generates the Q matrix.

This input must take one of the following values, where m is the number of rows in matrix A, and n is the number of columns in matrix A.

Name Value Description
Full Size Q 0 The size of matrix Q is m-by-m, and the size of matrix R is m-by-n.
Economy Size Q 1 The size of matrix Q is m-by-min(m, n), and the size of matrix R is min(m, n)-by-n.
No Q 2 The node does not generate matrix Q, and the size of matrix R is min(m, n)-by-n.

Default: Full Size Q ## 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 ## matrix Q

The orthogonal matrix. ## matrix R

The upper triangular matrix. ## matrix P

The n-by-n permutation matrix, where n is the number of columns in the input matrix.

If pivot? is False, this output is an empty array. ## 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 Performing QR Decomposition

The following equation defines the QR decomposition:

$A=QR=\left\{\begin{array}{cc}Q\left(\begin{array}{c}{R}_{1}\\ 0\end{array}\right)& m\ge n\\ Q\left(\begin{array}{cc}{R}_{1}& {R}_{2}\end{array}\right)& m

where

• m is the number of rows and n is the number of columns in matrix A
• matrix Q is an m-by-m unitary matrix
• matrix R is an m-by-n upper trapezoidal matrix
• matrix R1 is a k-by-k upper triangular matrix where k is the minimum of m and n
• R2 is an m-by-(n-m) submatrix of matrix R
• 0 is an (m-n)-by-m zero matrix

## Using QR Decomposition to Calculate the Determinant of a Square Matrix

You can use QR decomposition to calculate the determinant of a square matrix. For example, consider the following equation: det(A) = det(Q)*det(R). Because Q is orthogonal, the following is true: |det(Q)| = 1. Thus, the following also is true:

$|\mathrm{det}\left(A\right)|=|\mathrm{det}\left(R\right)|=|\underset{i}{\prod }{r}_{ii}|$

## Using QR Decomposition to Solve the Least-Squares Problem of a Linear System

You can use QR decomposition to solve the least-squares problem of a linear system Ax = b when A is full rank and mn. For example, consider the following system:

${‖b-Ax‖}_{2}={‖{Q}^{T}\left(b-Ax\right)‖}_{2}={‖\begin{array}{c}{Q}_{1}^{T}b-{R}_{1}x\\ {Q}_{2}^{T}b\end{array}‖}_{2}$

where the following are true:

• ${Q}^{T}=\left(\begin{array}{c}{Q}_{1}^{T}\\ {Q}_{2}^{T}\end{array}\right)$
• $R=\left(\begin{array}{c}{R}_{1}\\ 0\end{array}\right)$
• The size of Q1 is m-by-n
• The size of Q2 is m-by-(m - n)
• The size of R1 is n-by-n

Because min(||b - Ax||2) depends on min(||Q1Tb - R1x||2), you can obtain the solution x by solving the following new linear system: R1x = Q1Tb.

Where This Node Can Run:

Desktop OS: Windows

FPGA: Not supported

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