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

nag_matop_real_gen_sparse_lu (f01br) factorizes a real sparse matrix. The function either forms the LU$LU$ factorization of a permutation of the entire matrix, or, optionally, first permutes the matrix to block lower triangular form and then only factorizes the diagonal blocks.

Given a real sparse matrix A$A$, nag_matop_real_gen_sparse_lu (f01br) may be used to obtain the LU$LU$ factorization of a permutation of A$A$,

where P$P$ and Q$Q$ are permutation matrices, L$L$ is unit lower triangular and U$U$ is upper triangular. The function uses a sparse variant of Gaussian elimination, and the pivotal strategy is designed to compromise between maintaining sparsity and controlling loss of accuracy through round-off.

PAQ = LU
$$PAQ=LU$$ |

Optionally the function first permutes the matrix into block lower triangular form and then only factorizes the diagonal blocks. For some matrices this gives a considerable saving in storage and execution time.

Extensive data checks are made; duplicated nonzeros can be accumulated.

The factorization is intended to be used by nag_linsys_real_sparse_fac_solve (f04ax) to solve sparse systems of linear equations Ax = b$Ax=b$ or A^{T}x = b${A}^{\mathrm{T}}x=b$. If several matrices of the same sparsity pattern are to be factorized, nag_matop_real_gen_sparse_lu_reuse (f01bs) should be used for the second and subsequent matrices.

The method is fully described in Duff (1977).

A more recent algorithm for the same calculation is provided by nag_sparse_direct_real_gen_lu (f11me).

Duff I S (1977) MA28 – a set of Fortran subroutines for sparse unsymmetric linear equations *AERE Report R8730* HMSO

- 1: n – int64int32nag_int scalar
- n$n$, the order of the matrix A$A$.
- 2: nz – int64int32nag_int scalar
- The number of nonzero elements in the matrix A$A$.
- 3: a(licn) – double array
- 4: irn(lirn) – int64int32nag_int array
- 5: icn(licn) – int64int32nag_int array
- licn, the dimension of the array, must satisfy the constraint licn ≥ nz${\mathbf{licn}}\ge {\mathbf{nz}}$.icn(i)${\mathbf{icn}}\left(\mathit{i}\right)$, for i = 1,2, … ,nz$\mathit{i}=1,2,\dots ,{\mathbf{nz}}$, must contain, on entry, the column index of the nonzero element stored in a(i)${\mathbf{a}}\left(i\right)$. icn contains, on exit, the column indices of the nonzero elements in the factorization. The array must
**not**be changed by you between a call of nag_matop_real_gen_sparse_lu (f01br) and subsequent calls of nag_matop_real_gen_sparse_lu_reuse (f01bs) or nag_linsys_real_sparse_fac_solve (f04ax). - 6: abort(4$4$) – logical array
- If abort(1) = true${\mathbf{abort}}\left(1\right)=\mathbf{true}$, nag_matop_real_gen_sparse_lu (f01br) will exit immediately on detecting a structural singularity (one that depends on the pattern of nonzeros) and return ifail = 1${\mathbf{ifail}}={\mathbf{1}}$; otherwise it will complete the factorization (see Section [Singular and Rectangular Systems]).If abort(2) = true${\mathbf{abort}}\left(2\right)=\mathbf{true}$, nag_matop_real_gen_sparse_lu (f01br) will exit immediately on detecting a numerical singularity (one that depends on the numerical values) and return ifail = 2${\mathbf{ifail}}={\mathbf{2}}$; otherwise it will complete the factorization (see Section [Singular and Rectangular Systems]).If abort(3) = true${\mathbf{abort}}\left(3\right)=\mathbf{true}$, nag_matop_real_gen_sparse_lu (f01br) will exit immediately (with ifail = 5${\mathbf{ifail}}={\mathbf{5}}$) when the arrays a and icn are filled up by the previously factorized, active and unfactorized parts of the matrix; otherwise it continues so that better guidance on necessary array sizes can be given in idisp(6)${\mathbf{idisp}}\left(6\right)$ and idisp(7)${\mathbf{idisp}}\left(7\right)$, and will exit with ifail in the range 4$4$ to 6$6$. Note that there is always an immediate error exit if the array irn is too small.If abort(4) = true${\mathbf{abort}}\left(4\right)=\mathbf{true}$, nag_matop_real_gen_sparse_lu (f01br) exits immediately (with ifail = 13${\mathbf{ifail}}={\mathbf{13}}$) if it finds duplicate elements in the input matrix.If abort(4) = false${\mathbf{abort}}\left(4\right)=\mathbf{false}$, nag_matop_real_gen_sparse_lu (f01br) proceeds using a value equal to the sum of the duplicate elements. In either case details of each duplicate element are output on the current advisory message unit (see nag_file_set_unit_advisory (x04ab)), unless suppressed by the value of ifail on entry.

- 1: licn – int64int32nag_int scalar
*Default*: The dimension of the arrays a, icn. (An error is raised if these dimensions are not equal.)- 2: lirn – int64int32nag_int scalar
*Default*: The dimension of the array irn.- 3: pivot – double scalar
- Should have a value in the range 0.0 ≤ pivot ≤ 0.9999$0.0\le {\mathbf{pivot}}\le 0.9999$ and is used to control the choice of pivots. If pivot < 0.0${\mathbf{pivot}}<0.0$, the value 0.0$0.0$ is assumed, and if pivot > 0.9999${\mathbf{pivot}}>0.9999$, the value 0.9999$0.9999$ is assumed. When searching a row for a pivot, any element is excluded which is less than pivot times the largest of those elements in the row available as pivots. Thus decreasing pivot biases the algorithm to maintaining sparsity at the expense of stability.
*Default*: 0.1$0.1$ - 4: lblock – logical scalar
- If lblock = true${\mathbf{lblock}}=\mathbf{true}$, the matrix is preordered into block lower triangular form before the LU$LU$ factorization is performed; otherwise the entire matrix is factorized.
*Default*: true$\mathbf{true}$ - 5: grow – logical scalar
- If grow = true${\mathbf{grow}}=\mathbf{true}$, then on exit w(1)${\mathbf{w}}\left(1\right)$ contains an estimate (an upper bound) of the increase in size of elements encountered during the factorization. If the matrix is well-scaled (see Section [Scaling]), then a high value for w(1)${\mathbf{w}}\left(1\right)$ indicates that the LU$LU$ factorization may be inaccurate and you should be wary of the results and perhaps increase the parameter pivot for subsequent runs (see Section [Accuracy]).
*Default*: true$\mathbf{true}$

- iw

- 1: a(licn) – double array
- The nonzero elements in the LU$LU$ factorization. The array must
**not**be changed by you between a call of nag_matop_real_gen_sparse_lu (f01br) and a call of nag_linsys_real_sparse_fac_solve (f04ax). - 2: irn(lirn) – int64int32nag_int array
- irn is overwritten and is not needed for subsequent calls of nag_matop_real_gen_sparse_lu_reuse (f01bs) or nag_linsys_real_sparse_fac_solve (f04ax).
- 3: icn(licn) – int64int32nag_int array
- 4: ikeep(5 × n$5\times {\mathbf{n}}$) – int64int32nag_int array
- Indexing information about the factorization.
- 5: w(n) – double array
- If grow = true${\mathbf{grow}}=\mathbf{true}$, w(1)${\mathbf{w}}\left(1\right)$ contains an estimate (an upper bound) of the increase in size of elements encountered during the factorization (see grow); the rest of the array is used as workspace.If grow = false${\mathbf{grow}}=\mathbf{false}$, the array is not used.
- 6: idisp(10$10$) – int64int32nag_int array
- Contains information about the factorization.idisp(1)${\mathbf{idisp}}\left(1\right)$ and idisp(2)${\mathbf{idisp}}\left(2\right)$ indicate the position in arrays a and icn of the first and last elements in the LU$LU$ factorization of the diagonal blocks. (idisp(2)${\mathbf{idisp}}\left(2\right)$ gives the number of nonzeros in the factorization.) idisp(1)${\mathbf{idisp}}\left(1\right)$ and idisp(2)${\mathbf{idisp}}\left(2\right)$ must not be changed by you between a call of nag_matop_real_gen_sparse_lu (f01br) and subsequent calls to nag_matop_real_gen_sparse_lu_reuse (f01bs) or nag_linsys_real_sparse_fac_solve (f04ax).idisp(3)${\mathbf{idisp}}\left(3\right)$ and idisp(4)${\mathbf{idisp}}\left(4\right)$ monitor the adequacy of ‘elbow room’ in the arrays irn and a (and icn) respectively, by giving the number of times that the data in these arrays has been compressed during the factorization to release more storage. If either idisp(3)${\mathbf{idisp}}\left(3\right)$ or idisp(4)${\mathbf{idisp}}\left(4\right)$ is quite large (say greater than 10$10$), it will probably pay you to increase the size of the corresponding array(s) for subsequent runs. If either is very low or zero, then you can perhaps save storage by reducing the size of the corresponding array(s).idisp(5)${\mathbf{idisp}}\left(5\right)$, when lblock = false${\mathbf{lblock}}=\mathbf{false}$, gives an upper bound on the rank of the matrix; when lblock = true${\mathbf{lblock}}=\mathbf{true}$, gives an upper bound on the sum of the ranks of the lower triangular blocks.idisp(6)${\mathbf{idisp}}\left(6\right)$ and idisp(7)${\mathbf{idisp}}\left(7\right)$ give the minimum size of arrays irn and a (and icn) respectively which would enable a successful run on an identical matrix (but some ‘elbow-room’ should be allowed – see Section [Further Comments]).
- 7: ifail – int64int32nag_int scalar
- ifail = 0${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

Errors or warnings detected by the function:

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

`W`ifail = − 2${\mathbf{ifail}}=-2$- Successful factorization of a numerically singular matrix (which may also be structurally singular) (see Section [Singular and Rectangular Systems]).

`W`ifail = − 1${\mathbf{ifail}}=-1$- Successful factorization of a structurally singular matrix (see Section [Singular and Rectangular Systems]).

- The matrix is structurally singular and the factorization has been abandoned (abort(1)${\mathbf{abort}}\left(1\right)$ was
**true**on entry).

- The matrix is numerically singular and the factorization has been abandoned (abort(2)${\mathbf{abort}}\left(2\right)$ was
**true**on entry).

- licn is too small: there is not enough space in the arrays a and icn to store the factorization. If abort(3)${\mathbf{abort}}\left(3\right)$ was
**false**on entry, the factorization has been completed but some of the LU$LU$ factors have been discarded to create space; idisp(7)${\mathbf{idisp}}\left(7\right)$ then gives the minimum value of licn (i.e., the minimum length of a and icn) required for a successful factorization of the same matrix.

On entry, n ≤ 0${\mathbf{n}}\le 0$.

On entry, nz ≤ 0${\mathbf{nz}}\le 0$.

- Duplicate elements have been found in the input matrix and the factorization has been abandoned (abort(4) = true${\mathbf{abort}}\left(4\right)=\mathbf{true}$ on entry).

The factorization obtained is exact for a perturbed matrix whose (i,j)$(i,j)$th element differs from a_{ij}${a}_{ij}$ by less than 3ερm_{ij}$3\epsilon \rho {m}_{ij}$ where ε$\epsilon $ is the machine precision, ρ$\rho $ is the growth value returned in w(1)${\mathbf{w}}\left(1\right)$ if grow = true${\mathbf{grow}}=\mathbf{true}$, and m_{ij}${m}_{ij}$ the number of Gaussian elimination operations applied to element (i,j)$(i,j)$. The value of m_{ij}${m}_{ij}$ is not greater than n$n$ and is usually much less. Small ρ$\rho $ values therefore guarantee accurate results, but unfortunately large ρ$\rho $ values may give a very pessimistic indication of accuracy.

The time required may be estimated very roughly from the number τ$\tau $ of nonzeros in the factorized form (output as idisp(2)${\mathbf{idisp}}\left(2\right)$) and for nag_matop_real_gen_sparse_lu (f01br) and its associates is

where our unit is the time for the inner loop of a full matrix code (e.g., solving a full set of equations takes about (1/3)n^{3}$\frac{1}{3}{n}^{3}$ units). Note that the faster nag_matop_real_gen_sparse_lu_reuse (f01bs) time makes it well worthwhile to use this for a sequence of problems with the same pattern.

nag_matop_real_gen_sparse_lu (f01br): | 5τ^{2} / n$5{\tau}^{2}/n$ units |

nag_matop_real_gen_sparse_lu_reuse (f01bs): | τ^{2} / n${\tau}^{2}/n$ units |

nag_linsys_real_sparse_fac_solve (f04ax): | 2τ$2\tau $ units |

It should be appreciated that τ$\tau $ varies widely from problem to problem. For network problems it may be little greater than nz, the number of nonzeros in A$A$; for discretization of two-dimensional and three-dimensional partial differential equations it may be about
3n
log_{2}n
$3n{\mathrm{log}}_{2}n$ and (1/2)n^{5 / 3}$\frac{1}{2}{n}^{5/3}$, respectively.

The time taken by nag_matop_real_gen_sparse_lu (f01br) to find the block lower triangular form (lblock = true${\mathbf{lblock}}=\mathbf{true}$) is typically 5 – 15%$5\u201315\%$ of the time taken by the function when it is not found (lblock = false${\mathbf{lblock}}=\mathbf{false}$). If the matrix is irreducible (idisp(9) = 1${\mathbf{idisp}}\left(9\right)=1$ after a call with lblock = true${\mathbf{lblock}}=\mathbf{true}$) then this time is wasted. Otherwise, particularly if the largest block is small (idisp(10) ≪ n${\mathbf{idisp}}\left(10\right)\ll n$), the consequent savings are likely to be greater.

The time taken to estimate growth (grow = true${\mathbf{grow}}=\mathbf{true}$) is typically under 20%$20\%$ of the overall time.

The overall time may be substantially increased if there is inadequate ‘elbow-room’ in the arrays a, irn and icn. When the sizes of the arrays are minimal (idisp(6)${\mathbf{idisp}}\left(6\right)$ and idisp(7)${\mathbf{idisp}}\left(7\right)$) it can execute as much as three times slower. Values of idisp(3)${\mathbf{idisp}}\left(3\right)$ and idisp(4)${\mathbf{idisp}}\left(4\right)$ greater than about 10$10$ indicate that it may be worthwhile to increase array sizes.

The use of a relative pivot tolerance pivot essentially presupposes that the matrix is well-scaled, i.e., that the matrix elements are broadly comparable in size. Practical problems are often naturally well-scaled but particular care is needed for problems containing mixed types of variables (for example millimetres and neutron fluxes).

It is envisaged that nag_matop_real_gen_sparse_lu (f01br) will almost always be called for square nonsingular matrices and that singularity indicates an error condition. However, even if the matrix is singular it is possible to complete the factorization. It is even possible for nag_linsys_real_sparse_fac_solve (f04ax) to solve a set of equations whose matrix is singular provided the set is consistent.

Two forms of singularity are possible. If the matrix would be singular for any values of the nonzeros (e.g., if it has a whole row of zeros), then we say it is structurally singular, and continue only if abort(1) = false${\mathbf{abort}}\left(1\right)=\mathbf{false}$. If the matrix is nonsingular by virtue of the particular values of the nonzeros, then we say that it is numerically singular and continue only if abort(2) = false${\mathbf{abort}}\left(2\right)=\mathbf{false}$, in which case an upper bound on the rank of the matrix is returned in idisp(5)${\mathbf{idisp}}\left(5\right)$ when lblock = false${\mathbf{lblock}}=\mathbf{false}$.

Rectangular matrices may be treated by setting n to the larger of the number of rows and numbers of columns and setting abort(1) = false${\mathbf{abort}}\left(1\right)=\mathbf{false}$.

The matrix A$A$ may consist of a sum of contributions from different sub-systems (for example finite elements). In such cases you may rely on nag_matop_real_gen_sparse_lu (f01br) to perform assembly, since duplicated elements are summed.

The following code may be used to compute the determinant of A$A$ (as the double variable deta) after a call of nag_matop_real_gen_sparse_lu (f01br):

deta = 1; id = idisp(1); for i = 1:n idg = id + ikeep(3*n+i); deta = deta*a(idg); if (ikeep(n+i) ~= i) deta = -deta; end if (ikeep(2*n+i) ~= i) deta = -deta; end id = id + ikeep(i); end

Open in the MATLAB editor: nag_matop_real_gen_sparse_lu_example

function nag_matop_real_gen_sparse_lu_examplen = int64(6); nz = int64(15); a = zeros(150,1); a(1:15) = [5; 2; -1; 2; 3; -2; 1; 1; -1; -1; 2; -3; -1; -1; 6]; irn = zeros(75,1,'int64'); irn(1:15) = [int64(1);2;2;2;3;4; ... 4;4;5;5;5;5; ... 6;6;6]; icn = zeros(150,1,'int64'); icn(1:15) = [int64(1);2;3;4;3;1; ... 4;5;1;4;5;6; ... 1;2;6]; abort = [true; true; false; true]; [aOut, irnOut, icnOut, ikeep, w, idisp, ifail] = ... nag_matop_real_gen_sparse_lu(n, nz, a, irn, icn, abort); w, idisp, ifail

w = 18.0000 0 2.0000 0.5000 0 0 idisp = 5 16 0 0 6 15 19 6 3 4 ifail = 0

Open in the MATLAB editor: f01br_example

function f01br_examplen = int64(6); nz = int64(15); a = zeros(150,1); a(1:15) = [5; 2; -1; 2; 3; -2; 1; 1; -1; -1; 2; -3; -1; -1; 6]; irn = zeros(75,1,'int64'); irn(1:15) = [int64(1);2;2;2;3;4; ... 4;4;5;5;5;5; ... 6;6;6]; icn = zeros(150,1,'int64'); icn(1:15) = [int64(1);2;3;4;3;1; ... 4;5;1;4;5;6; ... 1;2;6]; abort = [true; true; false; true]; [aOut, irnOut, icnOut, ikeep, w, idisp, ifail] = f01br(n, nz, a, irn, icn, abort); w, idisp, ifail

w = 18.0000 0 2.0000 0.5000 0 0 idisp = 5 16 0 0 6 15 19 6 3 4 ifail = 0

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013