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_sparse_direct_real_gen_cond (f11mg)

## Purpose

nag_sparse_direct_real_gen_cond (f11mg) computes an estimate of the reciprocal of the condition number of a sparse matrix given an $LU$ factorization of the matrix computed by nag_sparse_direct_real_gen_lu (f11me).

## Syntax

[rcond, ifail] = f11mg(norm_p, n, il, lval, iu, uval, anorm)
[rcond, ifail] = nag_sparse_direct_real_gen_cond(norm_p, n, il, lval, iu, uval, anorm)

## Description

nag_sparse_direct_real_gen_cond (f11mg) estimates the condition number of a real sparse matrix $A$, in either the $1$-norm or the $\infty$-norm:
 $κ1A=A1 A-11 or κ∞A=A∞ A-1∞.$
Note that ${\kappa }_{\infty }\left(A\right)={\kappa }_{1}\left({A}^{\mathrm{T}}\right)$.
Because the condition number is infinite if $A$ is singular, the function actually returns an estimate of the reciprocal of the condition number.
The function should be preceded by a call to nag_sparse_direct_real_gen_norm (f11ml) to compute ${‖A‖}_{1}$ or ${‖A‖}_{\infty }$, and a call to nag_sparse_direct_real_gen_lu (f11me) to compute the $LU$ factorization of $A$. The function then estimates ${‖{A}^{-1}‖}_{1}$ or ${‖{A}^{-1}‖}_{\infty }$ and computes the reciprocal of the condition number.

None.

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{norm_p}$ – string (length ≥ 1)
Indicates whether ${\kappa }_{1}\left(A\right)$ or ${\kappa }_{\infty }\left(A\right)$ is to be estimated.
${\mathbf{norm_p}}=\text{'1'}$ or $\text{'O'}$
${\kappa }_{1}\left(A\right)$ is estimated.
${\mathbf{norm_p}}=\text{'I'}$
${\kappa }_{\infty }\left(A\right)$ is estimated.
Constraint: ${\mathbf{norm_p}}=\text{'1'}$, $\text{'O'}$ or $\text{'I'}$.
2:     $\mathrm{n}$int64int32nag_int scalar
$n$, the order of the matrix $A$.
Constraint: ${\mathbf{n}}\ge 0$.
3:     $\mathrm{il}\left(:\right)$int64int32nag_int array
The dimension of the array il must be at least as large as the dimension of the array of the same name in nag_sparse_direct_real_gen_lu (f11me)
Records the sparsity pattern of matrix $L$ as computed by nag_sparse_direct_real_gen_lu (f11me).
4:     $\mathrm{lval}\left(:\right)$ – double array
The dimension of the array lval must be at least as large as the dimension of the array of the same name in nag_sparse_direct_real_gen_lu (f11me)
Records the nonzero values of matrix $L$ and some nonzero values of matrix $U$ as computed by nag_sparse_direct_real_gen_lu (f11me).
5:     $\mathrm{iu}\left(:\right)$int64int32nag_int array
The dimension of the array iu must be at least as large as the dimension of the array of the same name in nag_sparse_direct_real_gen_lu (f11me)
Records the sparsity pattern of matrix $U$ as computed by nag_sparse_direct_real_gen_lu (f11me).
6:     $\mathrm{uval}\left(:\right)$ – double array
The dimension of the array uval must be at least as large as the dimension of the array of the same name in nag_sparse_direct_real_gen_lu (f11me)
Records some nonzero values of matrix $U$ as computed by nag_sparse_direct_real_gen_lu (f11me).
7:     $\mathrm{anorm}$ – double scalar
If ${\mathbf{norm_p}}=\text{'1'}$ or $\text{'O'}$, the $1$-norm of the matrix $A$.
If ${\mathbf{norm_p}}=\text{'I'}$, the $\infty$-norm of the matrix $A$.
anorm may be computed by calling nag_sparse_direct_real_gen_norm (f11ml) with the same value for the argument norm_p.
Constraint: ${\mathbf{anorm}}\ge 0.0$.

None.

### Output Parameters

1:     $\mathrm{rcond}$ – double scalar
An estimate of the reciprocal of the condition number of $A$. rcond is set to zero if exact singularity is detected or the estimate underflows. If rcond is less than machine precision, $A$ is singular to working precision.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
Constraint: ${\mathbf{anorm}}\ge 0.0$.
Constraint: ${\mathbf{n}}\ge 0$.
On entry, ${\mathbf{norm_p}}=_$.
Constraint: ${\mathbf{norm_p}}=\text{'1'}$, $\text{'O'}$ or $\text{'I'}$.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

The computed estimate rcond is never less than the true value $\rho$, and in practice is nearly always less than $10\rho$, although examples can be constructed where rcond is much larger.

A call to nag_sparse_direct_real_gen_cond (f11mg) involves solving a number of systems of linear equations of the form $Ax=b$ or ${A}^{\mathrm{T}}x=b$.

## Example

This example estimates the condition number in the $1$-norm of the matrix $A$, where
 $A= 2.00 1.00 0 0 0 0 0 1.00 -1.00 0 4.00 0 1.00 0 1.00 0 0 0 1.00 2.00 0 -2.00 0 0 3.00 .$
Here $A$ is nonsymmetric and must first be factorized by nag_sparse_direct_real_gen_lu (f11me). The true condition number in the $1$-norm is $20.25$.
```function f11mg_example

fprintf('f11mg example results\n\n');

% Sparse matrix A
n      = int64(5);
a      = [        2;  4; 1; -2; 1;  1; -1; 1; 1; 2; 3];
icolzp = [int64(1); 3; 5;  7; 9; 12];
irowix = [int64(1); 3; 1;  5; 2;  3;  2; 4; 3; 4; 5];
nz     = icolzp(n+1) - 1;

% Calculate COLAMD permutation
spec   = 'M';
iprm   = zeros(7*n, 1, 'int64');

[iprm, ifail] = f11md( ...
spec, n, icolzp, irowix, iprm);

% Factorise
thresh = 1;
nzlmx  = int64(8*nz);
nzlumx = int64(8*nz);
nzumx  = int64(8*nz);

[iprm, nzlumx, il, lval, iu, uval, nnzl, nnzu, flop, ifail] = ...
f11me( ...
n, irowix, a, iprm, thresh, nzlmx, nzlumx, nzumx);

% Calculate Norm
norm_p = '1';
[anorm, ifail] = f11ml( ...
norm_p, n, icolzp, irowix, a);

% Calculate condition number
[rcond, ifail] = f11mg( ...
norm_p, n, il, lval, iu, uval, anorm);

fprintf('Norm             = %7.3f\n', anorm);
fprintf('Condition number = %7.3f\n', 1/rcond);

```
```f11mg example results

Norm             =   6.000
Condition number =  20.250
```