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_det_real_gen (f03ba)

## Purpose

nag_det_real_gen (f03ba) computes the determinant of a real $n$ by $n$ matrix $A$. nag_lapack_dgetrf (f07ad) must be called first to supply the matrix $A$ in factorized form.

## Syntax

[d, id, ifail] = f03ba(a, ipiv, 'n', n)
[d, id, ifail] = nag_det_real_gen(a, ipiv, 'n', n)

## Description

nag_det_real_gen (f03ba) computes the determinant of a real $n$ by $n$ matrix $A$ that has been factorized by a call to nag_lapack_dgetrf (f07ad). The determinant of $A$ is the product of the diagonal elements of $U$ with the correct sign determined by the row interchanges.

## References

Wilkinson J H and Reinsch C (1971) Handbook for Automatic Computation II, Linear Algebra Springer–Verlag

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{a}\left(\mathit{lda},:\right)$ – double array
The first dimension of the array a must be at least ${\mathbf{n}}$.
The second dimension of the array a must be at least ${\mathbf{n}}$.
The $n$ by $n$ matrix $A$ in factorized form as returned by nag_lapack_dgetrf (f07ad).
2:     $\mathrm{ipiv}\left({\mathbf{n}}\right)$int64int32nag_int array
The row interchanges used to factorize matrix $A$ as returned by nag_lapack_dgetrf (f07ad).

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the first dimension of the array a and the dimension of the array ipiv. (An error is raised if these dimensions are not equal.)
$n$, the order of the matrix $A$.
Constraint: ${\mathbf{n}}>0$.

### Output Parameters

1:     $\mathrm{d}$ – double scalar
2:     $\mathrm{id}$int64int32nag_int scalar
The determinant of $A$ is given by ${\mathbf{d}}×{2.0}^{{\mathbf{id}}}$. It is given in this form to avoid overflow or underflow.
3:     $\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{n}}\ge 1$.
${\mathbf{ifail}}=3$
Constraint: $\mathit{lda}\ge {\mathbf{n}}$.
${\mathbf{ifail}}=4$
The matrix $A$ is approximately singular.
${\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 accuracy of the determinant depends on the conditioning of the original matrix. For a detailed error analysis, see page 107 of Wilkinson and Reinsch (1971).

The time taken by nag_det_real_gen (f03ba) is approximately proportional to $n$.

## Example

This example computes the $LU$ factorization with partial pivoting, and calculates the determinant, of the real matrix
 $33 16 72 -24 -10 -57 -8 -4 -17 .$
```function f03ba_example

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

a = [ 33,  16,  72;
-24, -10, -57;
-8,  -4, -17];
% Compute LU factorisation of a

fprintf('\n');
[ifail] = x04ca('g', 'n', a, 'Array a after factorization');

fprintf('\nPivots:\n');
fprintf(' %d', ipiv);
fprintf('\n\n');

[d, id, ifail] = f03ba(a, ipiv);

fprintf('d = %13.5f id = %d\n', d, id);
fprintf('Value of determinant = %13.5e\n', d*2^id);

```
```f03ba example results

Array a after factorization
1          2          3
1     33.0000    16.0000    72.0000
2     -0.7273     1.6364    -4.6364
3     -0.2424    -0.0741     0.1111

Pivots:
1 2 3

d =       0.37500 id = 4
Value of determinant =   6.00000e+00
```