Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_lapack_dgeequ (f07af)

## Purpose

nag_lapack_dgeequ (f07af) computes diagonal scaling matrices DR ${D}_{R}$ and DC ${D}_{C}$ intended to equilibrate a real m $m$ by n $n$ matrix A $A$ and reduce its condition number.

## Syntax

[r, c, rowcnd, colcnd, amax, info] = f07af(a, 'm', m, 'n', n)
[r, c, rowcnd, colcnd, amax, info] = nag_lapack_dgeequ(a, 'm', m, 'n', n)

## Description

nag_lapack_dgeequ (f07af) computes the diagonal scaling matrices. The diagonal scaling matrices are chosen to try to make the elements of largest absolute value in each row and column of the matrix B $B$ given by
 B = DRADC $B=DRADC$
have absolute value 1$1$. The diagonal elements of DR ${D}_{R}$ and DC ${D}_{C}$ are restricted to lie in the safe range (δ,1 / δ) $\left(\delta ,1/\delta \right)$, where δ $\delta$ is the value returned by function nag_machine_real_safe (x02am). Use of these scaling factors is not guaranteed to reduce the condition number of A $A$ but works well in practice.

None.

## Parameters

### Compulsory Input Parameters

1:     a(lda, : $:$) – double array
The first dimension of the array a must be at least max (1,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$
The second dimension of the array must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The matrix A$A$ whose scaling factors are to be computed.

### Optional Input Parameters

1:     m – int64int32nag_int scalar
Default: The first dimension of the array a.
m$m$, the number of rows of the matrix A$A$.
Constraint: m0${\mathbf{m}}\ge 0$.
2:     n – int64int32nag_int scalar
Default: The second dimension of the array a.
n$n$, the number of columns of the matrix A$A$.
Constraint: n0${\mathbf{n}}\ge 0$.

lda

### Output Parameters

1:     r(m) – double array
If ${\mathbf{INFO}}={\mathbf{0}}$ or ${\mathbf{INFO}}>\mathbf{m}$, r contains the row scale factors, the diagonal elements of DR${D}_{R}$. The elements of r will be positive.
2:     c(n) – double array
If ${\mathbf{INFO}}={\mathbf{0}}$, c contains the column scale factors, the diagonal elements of DC${D}_{C}$. The elements of c will be positive.
3:     rowcnd – double scalar
If ${\mathbf{INFO}}={\mathbf{0}}$ or ${\mathbf{INFO}}>\mathbf{m}$, rowcnd contains the ratio of the smallest value of r(i)${\mathbf{r}}\left(i\right)$ to the largest value of r(i)${\mathbf{r}}\left(i\right)$. If rowcnd0.1${\mathbf{rowcnd}}\ge 0.1$ and amax is neither too large nor too small, it is not worth scaling by DR${D}_{R}$.
4:     colcnd – double scalar
If ${\mathbf{INFO}}={\mathbf{0}}$, colcnd contains the ratio of the smallest value of c(i)${\mathbf{c}}\left(i\right)$ to the largest value of c(i)${\mathbf{c}}\left(i\right)$.
If colcnd0.1${\mathbf{colcnd}}\ge 0.1$, it is not worth scaling by DC${D}_{C}$.
5:     amax – double scalar
max|aij|$\mathrm{max}|{a}_{ij}|$. If amax is very close to overflow or underflow, the matrix A$A$ should be scaled.
6:     info – int64int32nag_int scalar
info = 0${\mathbf{info}}=0$ unless the function detects an error (see Section [Error Indicators and Warnings]).

## Error Indicators and Warnings

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

info = i${\mathbf{info}}=-i$
If info = i${\mathbf{info}}=-i$, parameter i$i$ had an illegal value on entry. The parameters are numbered as follows:
1: m, 2: n, 3: a, 4: lda, 5: r, 6: c, 7: rowcnd, 8: colcnd, 9: amax, 10: info.
It is possible that info refers to a parameter that is omitted from the MATLAB interface. This usually indicates that an error in one of the other input parameters has caused an incorrect value to be inferred.
W INFO > 0andINFOM${\mathbf{INFO}}>0 \text{and} {\mathbf{INFO}}\le {\mathbf{M}}$
If info = i${\mathbf{info}}=i$, the i$i$th row of A$A$ is exactly zero.
W ${\mathbf{INFO}}>{\mathbf{M}}$
If info = i${\mathbf{info}}=i$, the (im)$\left(i-{\mathbf{m}}\right)$th column of A$A$ is exactly zero.

## Accuracy

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

The complex analogue of this function is nag_lapack_zgeequ (f07at).

## Example

```function nag_lapack_dgeequ_example
n = 4;
a = [18000000000, 28800000000, 2.05, -8900000000;
5.25, -2.95, -9.5e-09, -3.8;
1.58, -2.69, -2.9e-10, -1.04;
-1.11, -0.66, -5.9e-11, 0.8];
thresh = 0.1;

% Compute row and column scaling factors
[r, c, rowcnd, colcnd, amax, info] = nag_lapack_dgeequ(a);

if info > 0
if info <= n
error('Row %d of A is exactly zero', info);
else
error('Column %d of A is exactly zero', info - n);
end
end

% Print ROWCND, COLCND, AMAX and the scale factors
format shorte
fprintf('\nROWCND = %8.1e COLCND = %8.1e AMAX = %8.1e\n', rowcnd, colcnd, amax);
fprintf('\nRow scale factors:\n');
disp(r');
fprintf('Column scale factors:\n');
disp(c');

% Compute values close to underflow and overflow
small = nag_machine_real_safe/(nag_machine_precision*nag_machine_model_base);
big = 1/small;

if (rowcnd >= thresh) && (amax >= small) && (amax <= big)
if (colcnd<thresh)
% Just column scale A
for j = 1:n
a(:, j) = c(j)* a(:, j);
end
end
elseif (colcnd>=thresh)
% Just row scale A
for j = 1:n
a(j, :) = r(j)* a(j, :);
end
else
% Row and column scale A
for j = 1:n
a(:, j) = c(j)* a(:, j);
a(j, :) = r(j)* a(j, :);
end
end

format short
fprintf('\nScaled Matrix:\n');
disp(a);
```
```

ROWCND =  3.9e-11 COLCND =  1.8e-09 AMAX =  2.9e+10

Row scale factors:
3.4722e-11   1.9048e-01   3.7175e-01   9.0090e-01

Column scale factors:
1.0000e+00   1.0000e+00   5.5263e+08   1.3816e+00

Scaled Matrix:
0.6250    1.0000    0.0393   -0.4269
1.0000   -0.5619   -1.0000   -1.0000
0.5874   -1.0000   -0.0596   -0.5341
-1.0000   -0.5946   -0.0294    0.9957

```
```function f07af_example
n = 4;
a = [18000000000, 28800000000, 2.05, -8900000000;
5.25, -2.95, -9.5e-09, -3.8;
1.58, -2.69, -2.9e-10, -1.04;
-1.11, -0.66, -5.9e-11, 0.8];
thresh = 0.1;

% Compute row and column scaling factors
[r, c, rowcnd, colcnd, amax, info] = f07af(a);

if info > 0
if info <= n
error('Row %d of A is exactly zero', info);
else
error('Column %d of A is exactly zero', info - n);
end
end

% Print ROWCND, COLCND, AMAX and the scale factors
format shorte
fprintf('\nROWCND = %8.1e COLCND = %8.1e AMAX = %8.1e\n', rowcnd, colcnd, amax);
fprintf('\nRow scale factors:\n');
disp(r');
fprintf('Column scale factors:\n');
disp(c');

% Compute values close to underflow and overflow
small = x02am/(x02aj*x02bh);
big = 1/small;

if (rowcnd >= thresh) && (amax >= small) && (amax <= big)
if (colcnd<thresh)
% Just column scale A
for j = 1:n
a(:, j) = c(j)* a(:, j);
end
end
elseif (colcnd>=thresh)
% Just row scale A
for j = 1:n
a(j, :) = r(j)* a(j, :);
end
else
% Row and column scale A
for j = 1:n
a(:, j) = c(j)* a(:, j);
a(j, :) = r(j)* a(j, :);
end
end

format short
fprintf('\nScaled Matrix:\n');
disp(a);
```
```

ROWCND =  3.9e-11 COLCND =  1.8e-09 AMAX =  2.9e+10

Row scale factors:
3.4722e-11   1.9048e-01   3.7175e-01   9.0090e-01

Column scale factors:
1.0000e+00   1.0000e+00   5.5263e+08   1.3816e+00

Scaled Matrix:
0.6250    1.0000    0.0393   -0.4269
1.0000   -0.5619   -1.0000   -1.0000
0.5874   -1.0000   -0.0596   -0.5341
-1.0000   -0.5946   -0.0294    0.9957

```