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_matop_real_gen_blkdiag_lu (f01lh)

## Purpose

nag_matop_real_gen_blkdiag_lu (f01lh) factorizes a real almost block diagonal matrix.

## Syntax

[a, pivot, tol, kpivot, ifail] = f01lh(n, blkstr, a, tol, 'nbloks', nbloks, 'lena', lena)
[a, pivot, tol, kpivot, ifail] = nag_matop_real_gen_blkdiag_lu(n, blkstr, a, tol, 'nbloks', nbloks, 'lena', lena)

## Description

nag_matop_real_gen_blkdiag_lu (f01lh) factorizes a real almost block diagonal matrix, A$A$, by row elimination with alternate row and column pivoting such that no ‘fill-in’ is produced. The code, which is derived from ARCECO described in Diaz et al. (1983), uses Level 1 and Level 2 BLAS. No three successive diagonal blocks may have columns in common and therefore the almost block diagonal matrix must have the form shown in the following diagram:
Figure 1
This function may be followed by nag_linsys_real_blkdiag_fac_solve (f04lh), which is designed to solve sets of linear equations AX = B$AX=B$ or ATX = B${A}^{\mathrm{T}}X=B$.

## References

Diaz J C, Fairweather G and Keast P (1983) Fortran packages for solving certain almost block diagonal linear systems by modified alternate row and column elimination ACM Trans. Math. Software 9 358–375

## Parameters

### Compulsory Input Parameters

1:     n – int64int32nag_int scalar
n$n$, the order of the matrix A$A$.
Constraint: n > 0${\mathbf{n}}>0$.
2:     blkstr(3$3$,nbloks) – int64int32nag_int array
Information which describes the block structure of A$A$ as follows:
• blkstr(1,k)${\mathbf{blkstr}}\left(1,k\right)$ must contain the number of rows in the k$k$th block, k = 1,2,,nbloks$k=1,2,\dots ,{\mathbf{nbloks}}$;
• blkstr(2,k)${\mathbf{blkstr}}\left(2,k\right)$ must contain the number of columns in the k$k$th block, k = 1,2,,nbloks$k=1,2,\dots ,{\mathbf{nbloks}}$;
• blkstr(3,k)${\mathbf{blkstr}}\left(3,k\right)$ must contain the number of columns of overlap between the k$k$th and (k + 1)$\left(k+1\right)$th blocks, k = 1,2,,nbloks1$k=1,2,\dots ,{\mathbf{nbloks}}-1$. blkstr(3,nbloks)${\mathbf{blkstr}}\left(3,{\mathbf{nbloks}}\right)$ need not be set.
The following conditions delimit the structure of A$A$:
• blkstr(1,k),blkstr(2,k) > 0,  k = 1,2,,nbloks${\mathbf{blkstr}}\left(1,k\right),{\mathbf{blkstr}}\left(2,k\right)>0\text{, }k=1,2,\dots ,{\mathbf{nbloks}}$,
• blkstr(3,k)0,   k = 1,2,,nbloks1${\mathbf{blkstr}}\left(3,k\right)\ge 0\text{, }k=1,2,\dots ,{\mathbf{nbloks}}-1$,
(there must be at least one column and one row in each block and a non-negative number of columns of overlap);
• blkstr(3,k1) + blkstr(3,k)blkstr(2,k),  k = 2,3,,nbloks1${\mathbf{blkstr}}\left(3,k-1\right)+{\mathbf{blkstr}}\left(3,k\right)\le {\mathbf{blkstr}}\left(2,k\right)\text{, }k=2,3,\dots ,{\mathbf{nbloks}}-1$,
(the total number of columns in overlaps in each block must not exceed the number of columns in that block);
• blkstr(2,1)blkstr(1,1)${\mathbf{blkstr}}\left(2,1\right)\ge {\mathbf{blkstr}}\left(1,1\right)$,
• blkstr(2,1) + k = 2 j [blkstr(2,k)blkstr(3, k 1 )] k = 1 j blkstr(1,k) ${\mathbf{blkstr}}\left(2,1\right)+\sum _{k=2}^{j}\left[{\mathbf{blkstr}}\left(2,k\right)-{\mathbf{blkstr}}\left(3,k-1\right)\right]\ge \sum _{k=1}^{j}{\mathbf{blkstr}}\left(1,k\right)$, j = 2,3,,nbloks1 $j=2,3,\dots ,{\mathbf{nbloks}}-1$,
• k = 1j[blkstr(2,k)blkstr(3,k)]k = 1jblkstr(1,k),  j = 1,2,,nbloks1$\sum _{k=1}^{j}\left[{\mathbf{blkstr}}\left(2,k\right)-{\mathbf{blkstr}}\left(3,k\right)\right]\le \sum _{k=1}^{j}{\mathbf{blkstr}}\left(1,k\right)\text{, }j=1,2,\dots ,{\mathbf{nbloks}}-1$,
(the index of the first column of the overlap between the j$j$th and (j + 1)$\left(j+1\right)$th blocks must be $\le$ the index of the last row of the j$j$th block, and the index of the last column of overlap must be $\ge$ the index of the last row of the j$j$th block);
• k = 1 nbloks blkstr(1,k) = n $\sum _{k=1}^{{\mathbf{nbloks}}}{\mathbf{blkstr}}\left(1,k\right)=n$,
• blkstr(2,1) + k = 2 nbloks [blkstr(2,k)blkstr(3, k 1 )] = nk ${\mathbf{blkstr}}\left(2,1\right)+\sum _{k=2}^{{\mathbf{nbloks}}}\left[{\mathbf{blkstr}}\left(2,k\right)-{\mathbf{blkstr}}\left(3,k-1\right)\right]=nk$,
(both the number of rows and the number of columns of A$A$ must equal n$n$).
3:     a(lena) – double array
lena, the dimension of the array, must satisfy the constraint lena k = 1 nbloks [blkstr(1,k) × blkstr(2,k)] ${\mathbf{lena}}\ge \sum _{k=1}^{{\mathbf{nbloks}}}\left[{\mathbf{blkstr}}\left(1,k\right)×{\mathbf{blkstr}}\left(2,k\right)\right]$.
The elements of the almost block diagonal matrix stored block by block, with each block stored column by column. The sizes of the blocks and the overlaps are defined by the parameter blkstr.
If ars${a}_{rs}$ is the first element in the k$k$th block, then an arbitrary element aij${a}_{ij}$ in the k$k$th block must be stored in the array element:
 a(pk + (j − r)mk + (i − s) + 1) $a(pk+(j-r)mk+(i-s)+1)$
where
 k − 1 pk = ∑ blkstr(1,l) × blkstr(2,l) l = 1
$pk=∑l= 1 k- 1blkstr1l×blkstr2l$
is the base address of the k$k$th block, and
 mk = blkstr(1,k) $mk=blkstr1k$
is the number of rows of the k$k$th block.
4:     tol – double scalar
A relative tolerance to be used to indicate whether or not the matrix is singular. For a discussion on how tol is used see Section [Further Comments]. If tol is non-positive, then tol is reset to 10ε$10\epsilon$, where ε$\epsilon$ is the machine precision.

### Optional Input Parameters

1:     nbloks – int64int32nag_int scalar
Default: The dimension of the array blkstr.
n$n$, the total number of blocks of the matrix A$A$.
Constraint: 0 < nbloksn$0<{\mathbf{nbloks}}\le {\mathbf{n}}$.
2:     lena – int64int32nag_int scalar
Default: The dimension of the array a.
The dimension of the array a as declared in the (sub)program from which nag_matop_real_gen_blkdiag_lu (f01lh) is called.
Constraint: lena k = 1 nbloks [blkstr(1,k) × blkstr(2,k)] ${\mathbf{lena}}\ge \sum _{k=1}^{{\mathbf{nbloks}}}\left[{\mathbf{blkstr}}\left(1,k\right)×{\mathbf{blkstr}}\left(2,k\right)\right]$.

None.

### Output Parameters

1:     a(lena) – double array
The factorized form of the matrix.
2:     pivot(n) – int64int32nag_int array
Details of the interchanges.
3:     tol – double scalar
Unchanged unless tol0.0${\mathbf{tol}}\le 0.0$ on entry, in which case it is set to 10ε$10\epsilon$.
4:     kpivot – int64int32nag_int scalar
If ${\mathbf{ifail}}={\mathbf{2}}$, kpivot contains the value k$k$, where k$k$ is the first position on the diagonal of the matrix A$A$ where too small a pivot was detected. Otherwise kpivot is set to 0$0$.
5:     ifail – int64int32nag_int scalar
${\mathrm{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:

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

ifail = 1${\mathbf{ifail}}=1$
 On entry, n < 1${\mathbf{n}}<1$, or nbloks < 1${\mathbf{nbloks}}<1$, or ${\mathbf{n}}<{\mathbf{nbloks}}$, or lena is too small, or illegal values detected in blkstr.
W ifail = 2${\mathbf{ifail}}=2$
The factorization has been completed, but a small pivot has been detected.

## Accuracy

The accuracy of nag_matop_real_gen_blkdiag_lu (f01lh) depends on the conditioning of the matrix A$A$.

Singularity or near singularity in A$A$ is determined by the parameter tol. If the absolute value of any pivot is less than tol × amax${\mathbf{tol}}×{a}_{\mathrm{max}}$, where amax${a}_{\mathrm{max}}$ is the maximum absolute value of an element of A$A$, then A$A$ is said to be singular. The position on the diagonal of A$A$ of the first of any such pivots is indicated by the parameter kpivot. The factorization, and the test for near singularity, will be more accurate if before entry A$A$ is scaled so that the $\infty$-norms of the rows and columns of A$A$ are all of approximately the same order of magnitude. (The $\infty$-norm is the maximum absolute value of any element in the row or column.)

## Example

```function nag_matop_real_gen_blkdiag_lu_example
n = int64(18);
blkstr = [int64(2),4,5,3,4;4,7,8,6,5;3,4,2,3,0];
a = [-1;
-1;
-0.98;
0.25;
-0.79;
-0.87;
-0.15;
0.35;
0.78;
-0.82;
-0.83;
-0.21;
0.31;
0.12;
-0.98;
-0.93;
-0.85;
-0.01;
-0.58;
-0.84;
0.89;
0.75;
0.04;
0.37;
-0.69;
0.32;
0.87;
-0.94;
-0.98;
-1;
0.38;
-0.96;
-0.76;
-0.53;
-1;
-1;
-0.99;
-0.87;
-0.93;
0.85;
0.17;
-0.91;
-0.14;
-0.91;
-0.39;
-1.37;
-0.28;
-1;
0.1;
0.79;
1.29;
0.9;
-0.59;
-0.89;
-0.71;
-1.59;
0.78;
-0.99;
-0.68;
0.39;
1.1;
-0.93;
0.21;
-0.09;
-0.99;
-1.63;
-0.76;
-0.73;
-0.58;
-0.12;
-1.01;
0.48;
-0.48;
-0.21;
-0.75;
-0.27;
0.08;
-0.67;
-0.24;
0.61;
0.56;
-0.41;
0.54;
-0.99;
0.4;
-0.41;
0.16;
-0.93;
0.16;
-0.16;
0.7;
-0.46;
0.98;
0.43;
0.71;
-0.47;
-0.25;
0.89;
-0.97;
-0.98;
-0.92;
-0.94;
-0.6;
-0.73;
-0.52;
-0.54;
-0.3;
0.07;
-0.46;
-1;
0.18;
0.04;
-0.58;
-0.36];
tol = 0;
[aOut, pivot, tolOut, index, ifail] = nag_matop_real_gen_blkdiag_lu(n, blkstr, a, tol)
```
```

aOut =

-1.0000
1.0000
-0.9800
1.2300
-0.7900
-0.0800
-0.1500
0.5000
0.6341
-0.6667
-0.6748
-0.1707
-1.0340
-0.3489
-0.0645
0.9126
-0.2426
-1.2517
-0.2458
0.4260
0.3800
-0.8474
-1.1838
0.7989
0.8700
-0.3865
0.2811
-1.7939
0.0400
0.9040
0.9748
-0.8304
-1.0000
-1.1089
-0.8671
1.0778
0.2365
0.8447
-0.0845
-0.6673
-1.0897
0.5443
0.2104
0.4940
0.1128
0.5929
1.7246
-0.8806
-0.4456
0.9244
-0.2536
-3.1739
-2.8793
0.3112
-0.5292
0.7990
1.1000
-0.0213
1.2768
-0.4998
-0.3007
-1.6300
-1.2254
-1.2751
-0.7689
-0.1200
-0.2700
-0.7178
0.5830
-0.5889
0.3997
-1.0100
-1.6194
-0.7062
-0.3962
0.1979
1.5262
1.4011
-1.0258
-0.9473
0.2344
0.0391
-0.9900
0.7720
0.5682
0.9800
-0.6897
0.7836
-0.1600
0.1975
0.5940
0.1600
-0.4475
-0.6820
-0.7657
-0.9316
-0.6636
-0.6891
-0.5306
0.8039
0.9708
0.9909
0.4200
-1.4430
0.1524
0.7753
-1.0000
0.8739
0.5376
-0.2729
-0.3600
0.3294
0.4793
-0.3479

pivot =

1
2
3
3
6
5
5
2
5
4
8
2
2
6
4
2
4
4

tolOut =

1.1102e-15

index =

0

ifail =

0

```
```function f01lh_example
n = int64(18);
blkstr = [int64(2),4,5,3,4;4,7,8,6,5;3,4,2,3,0];
a = [-1;
-1;
-0.98;
0.25;
-0.79;
-0.87;
-0.15;
0.35;
0.78;
-0.82;
-0.83;
-0.21;
0.31;
0.12;
-0.98;
-0.93;
-0.85;
-0.01;
-0.58;
-0.84;
0.89;
0.75;
0.04;
0.37;
-0.69;
0.32;
0.87;
-0.94;
-0.98;
-1;
0.38;
-0.96;
-0.76;
-0.53;
-1;
-1;
-0.99;
-0.87;
-0.93;
0.85;
0.17;
-0.91;
-0.14;
-0.91;
-0.39;
-1.37;
-0.28;
-1;
0.1;
0.79;
1.29;
0.9;
-0.59;
-0.89;
-0.71;
-1.59;
0.78;
-0.99;
-0.68;
0.39;
1.1;
-0.93;
0.21;
-0.09;
-0.99;
-1.63;
-0.76;
-0.73;
-0.58;
-0.12;
-1.01;
0.48;
-0.48;
-0.21;
-0.75;
-0.27;
0.08;
-0.67;
-0.24;
0.61;
0.56;
-0.41;
0.54;
-0.99;
0.4;
-0.41;
0.16;
-0.93;
0.16;
-0.16;
0.7;
-0.46;
0.98;
0.43;
0.71;
-0.47;
-0.25;
0.89;
-0.97;
-0.98;
-0.92;
-0.94;
-0.6;
-0.73;
-0.52;
-0.54;
-0.3;
0.07;
-0.46;
-1;
0.18;
0.04;
-0.58;
-0.36];
tol = 0;
[aOut, pivot, tolOut, index, ifail] = f01lh(n, blkstr, a, tol)
```
```

aOut =

-1.0000
1.0000
-0.9800
1.2300
-0.7900
-0.0800
-0.1500
0.5000
0.6341
-0.6667
-0.6748
-0.1707
-1.0340
-0.3489
-0.0645
0.9126
-0.2426
-1.2517
-0.2458
0.4260
0.3800
-0.8474
-1.1838
0.7989
0.8700
-0.3865
0.2811
-1.7939
0.0400
0.9040
0.9748
-0.8304
-1.0000
-1.1089
-0.8671
1.0778
0.2365
0.8447
-0.0845
-0.6673
-1.0897
0.5443
0.2104
0.4940
0.1128
0.5929
1.7246
-0.8806
-0.4456
0.9244
-0.2536
-3.1739
-2.8793
0.3112
-0.5292
0.7990
1.1000
-0.0213
1.2768
-0.4998
-0.3007
-1.6300
-1.2254
-1.2751
-0.7689
-0.1200
-0.2700
-0.7178
0.5830
-0.5889
0.3997
-1.0100
-1.6194
-0.7062
-0.3962
0.1979
1.5262
1.4011
-1.0258
-0.9473
0.2344
0.0391
-0.9900
0.7720
0.5682
0.9800
-0.6897
0.7836
-0.1600
0.1975
0.5940
0.1600
-0.4475
-0.6820
-0.7657
-0.9316
-0.6636
-0.6891
-0.5306
0.8039
0.9708
0.9909
0.4200
-1.4430
0.1524
0.7753
-1.0000
0.8739
0.5376
-0.2729
-0.3600
0.3294
0.4793
-0.3479

pivot =

1
2
3
3
6
5
5
2
5
4
8
2
2
6
4
2
4
4

tolOut =

1.1102e-15

index =

0

ifail =

0

```