# NAG Library Routine Document

## 1Purpose

f04mcf computes the approximate solution of a system of real linear equations with multiple right-hand sides, $AX=B$, where $A$ is a symmetric positive definite variable-bandwidth matrix, which has previously been factorized by f01mcf. Related systems may also be solved.

## 2Specification

Fortran Interface
 Subroutine f04mcf ( n, al, lal, d, nrow, ir, b, ldb, x, ldx,
 Integer, Intent (In) :: n, lal, nrow(n), ir, ldb, iselct, ldx Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: al(lal), d(*), b(ldb,ir) Real (Kind=nag_wp), Intent (Inout) :: x(ldx,ir)
#include nagmk26.h
 void f04mcf_ ( const Integer *n, const double al[], const Integer *lal, const double d[], const Integer nrow[], const Integer *ir, const double b[], const Integer *ldb, const Integer *iselct, double x[], const Integer *ldx, Integer *ifail)

## 3Description

The normal use of this routine is the solution of the systems $AX=B$, following a call of f01mcf to determine the Cholesky factorization $A=LD{L}^{\mathrm{T}}$ of the symmetric positive definite variable-bandwidth matrix $A$.
However, the routine may be used to solve any one of the following systems of linear algebraic equations:
 1 $LD{L}^{\mathrm{T}}X=B$ (usual system), 2 $LDX=B$ (lower triangular system), 3 $D{L}^{\mathrm{T}}X=B$ (upper triangular system), 4 $L{L}^{\mathrm{T}}X=B$ 5 $LX=B$ (unit lower triangular system), 6 ${L}^{\mathrm{T}}X=B$ (unit upper triangular system).
$L$ denotes a unit lower triangular variable-bandwidth matrix of order $n$, $D$ a diagonal matrix of order $n$, and $B$ a set of right-hand sides.
The matrix $L$ is represented by the elements lying within its envelope, i.e., between the first nonzero of each row and the diagonal (see Section 10 for an example). The width ${\mathbf{nrow}}\left(i\right)$ of the $i$th row is the number of elements between the first nonzero element and the element on the diagonal inclusive.
Wilkinson J H and Reinsch C (1971) Handbook for Automatic Computation II, Linear Algebra Springer–Verlag

## 5Arguments

1:     $\mathbf{n}$ – IntegerInput
On entry: $n$, the order of the matrix $L$.
Constraint: ${\mathbf{n}}\ge 1$.
2:     $\mathbf{al}\left({\mathbf{lal}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: the elements within the envelope of the lower triangular matrix $L$, taken in row by row order, as returned by f01mcf. The unit diagonal elements of $L$ must be stored explicitly.
3:     $\mathbf{lal}$ – IntegerInput
On entry: the dimension of the array al as declared in the (sub)program from which f04mcf is called.
Constraint: ${\mathbf{lal}}\ge {\mathbf{nrow}}\left(1\right)+{\mathbf{nrow}}\left(2\right)+\dots +{\mathbf{nrow}}\left(n\right)$.
4:     $\mathbf{d}\left(*\right)$ – Real (Kind=nag_wp) arrayInput
Note: the dimension of the array d must be at least $1$ if ${\mathbf{iselct}}\ge 4$, and at least ${\mathbf{n}}$ otherwise.
On entry: the diagonal elements of the diagonal matrix $D$. d is not referenced if ${\mathbf{iselct}}\ge 4$.
5:     $\mathbf{nrow}\left({\mathbf{n}}\right)$ – Integer arrayInput
On entry: ${\mathbf{nrow}}\left(i\right)$ must contain the width of row $i$ of $L$, i.e., the number of elements between the first (leftmost) nonzero element and the element on the diagonal, inclusive.
Constraint: $1\le {\mathbf{nrow}}\left(i\right)\le i$.
6:     $\mathbf{ir}$ – IntegerInput
On entry: $r$, the number of right-hand sides.
Constraint: ${\mathbf{ir}}\ge 1$.
7:     $\mathbf{b}\left({\mathbf{ldb}},{\mathbf{ir}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: the $n$ by $r$ right-hand side matrix $B$. See also Section 9.
8:     $\mathbf{ldb}$ – IntegerInput
On entry: the first dimension of the array b as declared in the (sub)program from which f04mcf is called.
Constraint: ${\mathbf{ldb}}\ge {\mathbf{n}}$.
9:     $\mathbf{iselct}$ – IntegerInput
On entry: must specify the type of system to be solved, as follows:
${\mathbf{iselct}}=1$
Solve $LD{L}^{\mathrm{T}}X=B$.
${\mathbf{iselct}}=2$
Solve $LDX=B$.
${\mathbf{iselct}}=3$
Solve $D{L}^{\mathrm{T}}X=B$.
${\mathbf{iselct}}=4$
Solve $L{L}^{\mathrm{T}}X=B$.
${\mathbf{iselct}}=5$
Solve $LX=B$.
${\mathbf{iselct}}=6$
Solve ${L}^{\mathrm{T}}X=B$.
Constraint: ${\mathbf{iselct}}=1$, $2$, $3$, $4$, $5$ or $6$.
10:   $\mathbf{x}\left({\mathbf{ldx}},{\mathbf{ir}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: the $n$ by $r$ solution matrix $X$. See also Section 9.
11:   $\mathbf{ldx}$ – IntegerInput
On entry: the first dimension of the array x as declared in the (sub)program from which f04mcf is called.
Constraint: ${\mathbf{ldx}}\ge {\mathbf{n}}$.
12:   $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{n}}<1$, or for some $i$, ${\mathbf{nrow}}\left(i\right)<1$ or ${\mathbf{nrow}}\left(i\right)>i$, or ${\mathbf{lal}}<{\mathbf{nrow}}\left(1\right)+{\mathbf{nrow}}\left(2\right)+\cdots +{\mathbf{nrow}}\left({\mathbf{n}}\right)$.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{ir}}<1$, or ${\mathbf{ldb}}<{\mathbf{n}}$, or ${\mathbf{ldx}}<{\mathbf{n}}$.
${\mathbf{ifail}}=3$
 On entry, ${\mathbf{iselct}}<1$, or ${\mathbf{iselct}}>6$.
${\mathbf{ifail}}=4$
The diagonal matrix $D$ is singular, i.e., at least one of the elements of d is zero. This can only occur if ${\mathbf{iselct}}\le 3$.
${\mathbf{ifail}}=5$
At least one of the diagonal elements of $L$ is not equal to unity.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

The usual backward error analysis of the solution of triangular system applies: each computed solution vector is exact for slightly perturbed matrices $L$ and $D$, as appropriate (see pages 25–27 and 54–55 of Wilkinson and Reinsch (1971)).

## 8Parallelism and Performance

f04mcf is not threaded in any implementation.

The time taken by f04mcf is approximately proportional to $pr$, where $p={\mathbf{nrow}}\left(1\right)+{\mathbf{nrow}}\left(2\right)+\cdots +{\mathbf{nrow}}\left(n\right)$.
Unless otherwise stated in the Users' Note for your implementation, the routine may be called with the same actual array supplied for the arguments b and x, in which case the solution matrix will overwrite the right-hand side matrix. However this is not standard Fortran and may not work in all implementations.

## 10Example

This example solves the system of equations $AX=B$, where
 $A= 1 2 0 0 5 0 2 5 3 0 14 0 0 3 13 0 18 0 0 0 0 16 8 24 5 14 18 8 55 17 0 0 0 24 17 77 and B= 6 -10 15 -21 11 -3 0 24 51 -39 46 67$
Here $A$ is symmetric and positive definite and must first be factorized by f01mcf.

### 10.1Program Text

Program Text (f04mcfe.f90)

### 10.2Program Data

Program Data (f04mcfe.d)

### 10.3Program Results

Program Results (f04mcfe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017