# NAG CL Interfacef07gfc (dppequ)

## 1Purpose

f07gfc computes a diagonal scaling matrix $S$ intended to equilibrate a real $n$ by $n$ symmetric positive definite matrix $A$, stored in packed format, and reduce its condition number.

## 2Specification

 #include
 void f07gfc (Nag_OrderType order, Nag_UploType uplo, Integer n, const double ap[], double s[], double *scond, double *amax, NagError *fail)
The function may be called by the names: f07gfc, nag_lapacklin_dppequ or nag_dppequ.

## 3Description

f07gfc computes a diagonal scaling matrix $S$ chosen so that
 $sj=1 / ajj .$
This means that the matrix $B$ given by
 $B=SAS ,$
has diagonal elements equal to unity. This in turn means that the condition number of $B$, ${\kappa }_{2}\left(B\right)$, is within a factor $n$ of the matrix of smallest possible condition number over all possible choices of diagonal scalings (see Corollary 7.6 of Higham (2002)).

## 4References

Higham N J (2002) Accuracy and Stability of Numerical Algorithms (2nd Edition) SIAM, Philadelphia

## 5Arguments

1: $\mathbf{order}$Nag_OrderType Input
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by ${\mathbf{order}}=\mathrm{Nag_RowMajor}$. See Section 3.1.3 in the Introduction to the NAG Library CL Interface for a more detailed explanation of the use of this argument.
Constraint: ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ or $\mathrm{Nag_ColMajor}$.
2: $\mathbf{uplo}$Nag_UploType Input
On entry: indicates whether the upper or lower triangular part of $A$ is stored in the array ap, as follows:
${\mathbf{uplo}}=\mathrm{Nag_Upper}$
The upper triangle of $A$ is stored.
${\mathbf{uplo}}=\mathrm{Nag_Lower}$
The lower triangle of $A$ is stored.
Constraint: ${\mathbf{uplo}}=\mathrm{Nag_Upper}$ or $\mathrm{Nag_Lower}$.
3: $\mathbf{n}$Integer Input
On entry: $n$, the order of the matrix $A$.
Constraint: ${\mathbf{n}}\ge 0$.
4: $\mathbf{ap}\left[\mathit{dim}\right]$const double Input
Note: the dimension, dim, of the array ap must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×\left({\mathbf{n}}+1\right)/2\right)$.
On entry: the $n$ by $n$ symmetric matrix $A$, packed by rows or columns.
The storage of elements ${A}_{ij}$ depends on the order and uplo arguments as follows:
if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$ and ${\mathbf{uplo}}=\mathrm{Nag_Upper}$,
${A}_{ij}$ is stored in ${\mathbf{ap}}\left[\left(j-1\right)×j/2+i-1\right]$, for $i\le j$;
if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$ and ${\mathbf{uplo}}=\mathrm{Nag_Lower}$,
${A}_{ij}$ is stored in ${\mathbf{ap}}\left[\left(2n-j\right)×\left(j-1\right)/2+i-1\right]$, for $i\ge j$;
if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ and ${\mathbf{uplo}}=\mathrm{Nag_Upper}$,
${A}_{ij}$ is stored in ${\mathbf{ap}}\left[\left(2n-i\right)×\left(i-1\right)/2+j-1\right]$, for $i\le j$;
if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ and ${\mathbf{uplo}}=\mathrm{Nag_Lower}$,
${A}_{ij}$ is stored in ${\mathbf{ap}}\left[\left(i-1\right)×i/2+j-1\right]$, for $i\ge j$.
Only the elements of ap corresponding to the diagonal elements $A$ are referenced.
5: $\mathbf{s}\left[{\mathbf{n}}\right]$double Output
On exit: if ${\mathbf{fail}}\mathbf{.}\mathbf{code}=$ NE_NOERROR, s contains the diagonal elements of the scaling matrix $S$.
6: $\mathbf{scond}$double * Output
On exit: if ${\mathbf{fail}}\mathbf{.}\mathbf{code}=$ NE_NOERROR, scond contains the ratio of the smallest value of s to the largest value of s. If ${\mathbf{scond}}\ge 0.1$ and amax is neither too large nor too small, it is not worth scaling by $S$.
7: $\mathbf{amax}$double * Output
On exit: $\mathrm{max}\left|{a}_{ij}\right|$. If amax is very close to overflow or underflow, the matrix $A$ should be scaled.
8: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 0$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_MAT_NOT_POS_DEF
The $〈\mathit{\text{value}}〉$th diagonal element of $A$ is not positive (and hence $A$ cannot be positive definite).
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.

## 7Accuracy

The computed scale factors will be close to the exact scale factors.

## 8Parallelism and Performance

f07gfc is not threaded in any implementation.

The complex analogue of this function is f07gtc.

## 10Example

This example equilibrates the symmetric positive definite matrix $A$ given by
 $A = -4.16 -3.12×105 -0.56 -0.10 -3.12×105 -5.03×1010 -0.83×105 -1.18×105 -0.56 -0.83×105 -0.76 -0.34 -0.10 -1.18×105 -0.34 -1.18 .$
Details of the scaling factors and the scaled matrix are output.

### 10.1Program Text

Program Text (f07gfce.c)

### 10.2Program Data

Program Data (f07gfce.d)

### 10.3Program Results

Program Results (f07gfce.r)