f01 Chapter Contents
f01 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_real_qr (f01qcc)

## 1  Purpose

nag_real_qr (f01qcc) finds the $QR$ factorization of the real $m$ by $n$ matrix $A$, where $m\ge n$.

## 2  Specification

 #include #include
 void nag_real_qr (Integer m, Integer n, double a[], Integer tda, double zeta[], NagError *fail)

## 3  Description

The $m$ by $n$ matrix $A$ is factorized as
 $A = Q R 0 when ​ m > n , A = QR when ​ m = n ,$
where $Q$ is an $m$ by $m$ orthogonal matrix and $R$ is an $n$ by $n$ upper triangular matrix. The factorization is obtained by Householder's method. The $k$th transformation matrix, ${Q}_{k}$, which is used to introduce zeros into the $k$th column of $A$ is given in the form
 $Q k = I 0 0 T k$
where
 $T k = I - u k ukT ,$
 $u k = ζ k z k ,$
${\zeta }_{k}$ is a scalar and ${z}_{k}$ is an $\left(m-k\right)$ element vector. ${\zeta }_{k}$ and ${z}_{k}$ are chosen to annihilate the elements below the triangular part of $A$.
The vector ${u}_{k}$ is returned in the $\left(k-1\right)$th element of the array zeta and in the $\left(k-1\right)$th column of a, such that ${\zeta }_{k}$ is in ${\mathbf{zeta}}\left[k-1\right]$ and the elements of ${z}_{k}$ are in ${\mathbf{a}}\left[\left(k\right)×{\mathbf{tda}}+k-1\right],\dots ,{\mathbf{a}}\left[\left(m-1\right)×{\mathbf{tda}}+k-1\right]$. The elements of $R$ are returned in the upper triangular part of a. $Q$ is given by
 $Q = Q n Q n-1 ⋯ Q 1 T .$
Good background descriptions to the $QR$ factorization are given in Dongarra et al. (1979) and Golub and Van Loan (1996).

## 4  References

Dongarra J J, Moler C B, Bunch J R and Stewart G W (1979) LINPACK Users' Guide SIAM, Philadelphia
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
Wilkinson J H (1965) The Algebraic Eigenvalue Problem Oxford University Press, Oxford

## 5  Arguments

1:     mIntegerInput
On entry: $m$, the number of rows of $A$.
Constraint: ${\mathbf{m}}\ge {\mathbf{n}}$.
2:     nIntegerInput
On entry: $n$, the number of columns of $A$.
When ${\mathbf{n}}=0$ then an immediate return is effected.
Constraint: ${\mathbf{n}}\ge 0$.
3:     a[${\mathbf{m}}×{\mathbf{tda}}$]doubleInput/Output
On entry: the leading $m$ by $n$ part of the array a must contain the matrix to be factorized.
On exit: the $n$ by $n$ upper triangular part of a will contain the upper triangular matrix $R$ and the $m$ by $n$ strictly lower triangular part of a will contain details of the factorization as described in Section 3
4:     tdaIntegerInput
On entry: the stride separating matrix column elements in the array a.
Constraint: ${\mathbf{tda}}\ge {\mathbf{n}}$.
5:     zeta[n]doubleOutput
On exit: ${\mathbf{zeta}}\left[k-1\right]$ contains the scalar ${\zeta }_{k}$ for the $k$th transformation. If ${T}_{k}=I$ then zeta$\left(k-1\right)=0.0$, otherwise ${\mathbf{zeta}}\left[k-1\right]$ contains ${\zeta }_{k}$ as described in Section 3 and ${\zeta }_{k}$ is always in the range $\left(1.0,\sqrt{2.0}\right)$.
6:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_2_INT_ARG_LT
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$ while ${\mathbf{n}}=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{m}}\ge {\mathbf{n}}$.
On entry, ${\mathbf{tda}}=〈\mathit{\text{value}}〉$ while ${\mathbf{n}}=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{tda}}\ge {\mathbf{n}}$.
NE_INT_ARG_LT
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 0$.

## 7  Accuracy

The computed factors $Q$ and $R$ satisfy the relation
 $Q R 0 = A + E$
where $‖E‖\le c\epsilon ‖A‖$, and $\epsilon$ is the machine precision, $c$ is a modest function of $m$ and $n$ and $\text{.}$ denotes the spectral (two) norm.

The approximate number of floating point operations is given by $2{n}^{2}\left(3m-n\right)/3$.

## 9  Example

To obtain the $QR$ factorization of the 5 by 3 matrix
 $A = 2.0 2.5 2.5 2.0 2.5 2.5 1.6 -0.4 2.8 2.0 -0.5 0.5 1.2 -0.3 -2.9 .$

### 9.1  Program Text

Program Text (f01qcce.c)

### 9.2  Program Data

Program Data (f01qcce.d)

### 9.3  Program Results

Program Results (f01qcce.r)