# NAG Library Routine Document

## 1Purpose

f11mhf returns error bounds for the solution of a real sparse system of linear equations with multiple right-hand sides, $AX=B$ or ${A}^{\mathrm{T}}X=B$. It improves the solution by iterative refinement in standard precision, in order to reduce the backward error as much as possible.

## 2Specification

Fortran Interface
 Subroutine f11mhf ( n, a, iprm, il, lval, iu, uval, nrhs, b, ldb, x, ldx, ferr, berr,
 Integer, Intent (In) :: n, icolzp(*), irowix(*), iprm(7*n), il(*), iu(*), nrhs, ldb, ldx Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: a(*), lval(*), uval(*), b(ldb,*) Real (Kind=nag_wp), Intent (Inout) :: x(ldx,*) Real (Kind=nag_wp), Intent (Out) :: ferr(nrhs), berr(nrhs) Character (1), Intent (In) :: trans
C Header Interface
#include nagmk26.h
 void f11mhf_ (const char *trans, const Integer *n, const Integer icolzp[], const Integer irowix[], const double a[], const Integer iprm[], const Integer il[], const double lval[], const Integer iu[], const double uval[], const Integer *nrhs, const double b[], const Integer *ldb, double x[], const Integer *ldx, double ferr[], double berr[], Integer *ifail, const Charlen length_trans)

## 3Description

f11mhf returns the backward errors and estimated bounds on the forward errors for the solution of a real system of linear equations with multiple right-hand sides $AX=B$ or ${A}^{\mathrm{T}}X=B$. The routine handles each right-hand side vector (stored as a column of the matrix $B$) independently, so we describe the function of f11mhf in terms of a single right-hand side $b$ and solution $x$.
Given a computed solution $x$, the routine computes the component-wise backward error $\beta$. This is the size of the smallest relative perturbation in each element of $A$ and $b$ such that if $x$ is the exact solution of a perturbed system:
 $A+δA x = b + δ b then δaij ≤ β aij and δbi ≤ β bi .$
Then the routine estimates a bound for the component-wise forward error in the computed solution, defined by:
 $maxi xi - x^i / maxi xi$
where $\stackrel{^}{x}$ is the true solution.
The routine uses the $LU$ factorization ${P}_{r}A{P}_{c}=LU$ computed by f11mef and the solution computed by f11mff.

## 4References

Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore

## 5Arguments

1:     $\mathbf{trans}$ – Character(1)Input
On entry: specifies whether $AX=B$ or ${A}^{\mathrm{T}}X=B$ is solved.
${\mathbf{trans}}=\text{'N'}$
$AX=B$ is solved.
${\mathbf{trans}}=\text{'T'}$
${A}^{\mathrm{T}}X=B$ is solved.
Constraint: ${\mathbf{trans}}=\text{'N'}$ or $\text{'T'}$.
2:     $\mathbf{n}$ – IntegerInput
On entry: $n$, the order of the matrix $A$.
Constraint: ${\mathbf{n}}\ge 0$.
3:     $\mathbf{icolzp}\left(*\right)$ – Integer arrayInput
Note: the dimension of the array icolzp must be at least ${\mathbf{n}}+1$.
On entry: ${\mathbf{icolzp}}\left(i\right)$ contains the index in $A$ of the start of a new column. See Section 2.1.3 in the F11 Chapter Introduction.
4:     $\mathbf{irowix}\left(*\right)$ – Integer arrayInput
Note: the dimension of the array irowix must be at least ${\mathbf{icolzp}}\left({\mathbf{n}}+1\right)-1$, the number of nonzeros of the sparse matrix $A$.
On entry: the row index array of sparse matrix $A$.
5:     $\mathbf{a}\left(*\right)$ – Real (Kind=nag_wp) arrayInput
Note: the dimension of the array a must be at least ${\mathbf{icolzp}}\left({\mathbf{n}}+1\right)-1$, the number of nonzeros of the sparse matrix $A$.
On entry: the array of nonzero values in the sparse matrix $A$.
6:     $\mathbf{iprm}\left(7×{\mathbf{n}}\right)$ – Integer arrayInput
On entry: the column permutation which defines ${P}_{c}$, the row permutation which defines ${P}_{r}$, plus associated data structures as computed by f11mef.
7:     $\mathbf{il}\left(*\right)$ – Integer arrayInput
Note: the dimension of the array il must be at least as large as the dimension of the array of the same name in f11mef.
On entry: records the sparsity pattern of matrix $L$ as computed by f11mef.
8:     $\mathbf{lval}\left(*\right)$ – Real (Kind=nag_wp) arrayInput
Note: the dimension of the array lval must be at least as large as the dimension of the array of the same name in f11mef.
On entry: records the nonzero values of matrix $L$ and some nonzero values of matrix $U$ as computed by f11mef.
9:     $\mathbf{iu}\left(*\right)$ – Integer arrayInput
Note: the dimension of the array iu must be at least as large as the dimension of the array of the same name in f11mef.
On entry: records the sparsity pattern of matrix $U$ as computed by f11mef.
10:   $\mathbf{uval}\left(*\right)$ – Real (Kind=nag_wp) arrayInput
Note: the dimension of the array uval must be at least as large as the dimension of the array of the same name in f11mef.
On entry: records some nonzero values of matrix $U$ as computed by f11mef.
11:   $\mathbf{nrhs}$ – IntegerInput
On entry: $\mathit{nrhs}$, the number of right-hand sides in $B$.
Constraint: ${\mathbf{nrhs}}\ge 0$.
12:   $\mathbf{b}\left({\mathbf{ldb}},*\right)$ – Real (Kind=nag_wp) arrayInput
Note: the second dimension of the array b must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nrhs}}\right)$.
On entry: the $n$ by $\mathit{nrhs}$ right-hand side matrix $B$.
13:   $\mathbf{ldb}$ – IntegerInput
On entry: the first dimension of the array b as declared in the (sub)program from which f11mhf is called.
Constraint: ${\mathbf{ldb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
14:   $\mathbf{x}\left({\mathbf{ldx}},*\right)$ – Real (Kind=nag_wp) arrayInput/Output
Note: the second dimension of the array x must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nrhs}}\right)$.
On entry: the $n$ by $\mathit{nrhs}$ solution matrix $X$, as returned by f11mff.
On exit: the $n$ by $\mathit{nrhs}$ improved solution matrix $X$.
15:   $\mathbf{ldx}$ – IntegerInput
On entry: the first dimension of the array x as declared in the (sub)program from which f11mhf is called.
Constraint: ${\mathbf{ldx}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
16:   $\mathbf{ferr}\left({\mathbf{nrhs}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: ${\mathbf{ferr}}\left(\mathit{j}\right)$ contains an estimated error bound for the $\mathit{j}$th solution vector, that is, the $\mathit{j}$th column of $X$, for $\mathit{j}=1,2,\dots ,\mathit{nrhs}$.
17:   $\mathbf{berr}\left({\mathbf{nrhs}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: ${\mathbf{berr}}\left(\mathit{j}\right)$ contains the component-wise backward error bound $\beta$ for the $\mathit{j}$th solution vector, that is, the $\mathit{j}$th column of $X$, for $\mathit{j}=1,2,\dots ,\mathit{nrhs}$.
18:   $\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{ldb}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry, ${\mathbf{ldx}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldx}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 0$.
On entry, ${\mathbf{nrhs}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nrhs}}\ge 0$.
On entry, ${\mathbf{trans}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{trans}}=\text{'N'}$ or $\text{'T'}$.
${\mathbf{ifail}}=2$
Incorrect row permutations in array iprm.
${\mathbf{ifail}}=3$
Incorrect column permutations in array iprm.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
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 bounds returned in ferr are not rigorous, because they are estimated, not computed exactly; but in practice they almost always overestimate the actual error.

## 8Parallelism and Performance

f11mhf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
f11mhf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

## 9Further Comments

At most five steps of iterative refinement are performed, but usually only one or two steps are required.
Estimating the forward error involves solving a number of systems of linear equations of the form $Ax=b$ or ${A}^{\mathrm{T}}x=b$;

## 10Example

This example solves the system of equations $AX=B$ using iterative refinement and to compute the forward and backward error bounds, 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 and B= 1.56 3.12 -0.25 -0.50 3.60 7.20 1.33 2.66 0.52 1.04 .$
Here $A$ is nonsymmetric and must first be factorized by f11mef.

### 10.1Program Text

Program Text (f11mhfe.f90)

### 10.2Program Data

Program Data (f11mhfe.d)

### 10.3Program Results

Program Results (f11mhfe.r)

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