# NAG FL Interfacef01mdf (real_​modified_​cholesky)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

f01mdf computes the Cheng–Higham modified Cholesky factorization of a real symmetric matrix.

## 2Specification

Fortran Interface
 Subroutine f01mdf ( uplo, n, a, lda, ipiv,
 Integer, Intent (In) :: n, lda Integer, Intent (Inout) :: ipiv(n), ifail Real (Kind=nag_wp), Intent (In) :: delta Real (Kind=nag_wp), Intent (Inout) :: a(lda,*) Real (Kind=nag_wp), Intent (Out) :: offdiag(n) Character (1), Intent (In) :: uplo
#include <nag.h>
 void f01mdf_ (const char *uplo, const Integer *n, double a[], const Integer *lda, double offdiag[], Integer ipiv[], const double *delta, Integer *ifail, const Charlen length_uplo)
The routine may be called by the names f01mdf or nagf_matop_real_modified_cholesky.

## 3Description

Given a symmetric, possibly indefinite matrix $A$, f01mdf finds the Cheng–Higham modified Cholesky factorization
 $PT(A+E)P=LDLT ,$
when ${\mathbf{uplo}}=\text{'L'}$. Here $L$ is a unit lower triangular matrix, $P$ is a permutation matrix, $D$ is a symmetric block diagonal matrix (with blocks of order $1$ or $2$) with minimum eigenvalue $\delta$, and $E$ is a perturbation matrix of small norm chosen so that such a factorization can be found. Note that $E$ is not computed explicitly.
If ${\mathbf{uplo}}=\text{'U'}$, we compute the factorization ${P}^{\mathrm{T}}\left(A+E\right)P=UD{U}^{\mathrm{T}}$, where $U$ is a unit upper triangular matrix.
If the matrix $A$ is symmetric positive definite, the algorithm ensures that $E=0$. The routine f01mef can be used to compute the matrix $A+E$.
Ashcraft C, Grimes R G, and Lewis J G (1998) Accurate symmetric indefinite linear equation solvers SIAM J. Matrix Anal. Appl. 20 513–561
Cheng S H and Higham N J (1998) A modified Cholesky algorithm based on a symmetric indefinite factorization SIAM J. Matrix Anal. Appl. 19(4) 1097–1110

## 5Arguments

1: $\mathbf{uplo}$Character(1) Input
On entry: specifies whether the upper or lower triangular part of $A$ is stored and how $A$ is to be factorized.
${\mathbf{uplo}}=\text{'U'}$
The upper triangular part of $A$ is stored and we compute ${P}^{\mathrm{T}}\left(A+E\right)P=UD{U}^{\mathrm{T}}$.
${\mathbf{uplo}}=\text{'L'}$
The lower triangular part of $A$ is stored and we compute ${P}^{\mathrm{T}}\left(A+E\right)P=LD{L}^{\mathrm{T}}$.
Constraint: ${\mathbf{uplo}}=\text{'U'}$ or $\text{'L'}$.
2: $\mathbf{n}$Integer Input
On entry: $n$, the order of the matrix $A$.
Constraint: ${\mathbf{n}}>0$.
3: $\mathbf{a}\left({\mathbf{lda}},*\right)$Real (Kind=nag_wp) array Input/Output
Note: the second dimension of the array a must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry: the $n×n$ symmetric matrix $A$.
• If ${\mathbf{uplo}}=\text{'U'}$, the upper triangular part of $A$ must be stored and the elements of the array below the diagonal are not referenced.
• If ${\mathbf{uplo}}=\text{'L'}$, the lower triangular part of $A$ must be stored and the elements of the array above the diagonal are not referenced.
On exit: a is overwritten.
• If ${\mathbf{uplo}}=\text{'U'}$, the strictly upper triangular part of $A$ is overwritten and the elements of the array below the diagonal are not set.
• If ${\mathbf{uplo}}=\text{'L'}$, the strictly lower triangular part of $A$ is overwritten and the elements of the array above the diagonal are not set.
• The main diagonal elements of $A$ are overwritten by the main diagonal elements of matrix $D$.
See Section 9 for further details.
4: $\mathbf{lda}$Integer Input
On entry: the first dimension of the array a as declared in the (sub)program from which f01mdf is called.
Constraint: ${\mathbf{lda}}\ge {\mathbf{n}}$.
5: $\mathbf{offdiag}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: the offdiagonals of the symmetric matrix $D$ are returned in ${\mathbf{offdiag}}\left(1\right),{\mathbf{offdiag}}\left(2\right),\dots ,{\mathbf{offdiag}}\left(n-1\right)$, for ${\mathbf{uplo}}=\text{'L'}$ and in ${\mathbf{offdiag}}\left(2\right),{\mathbf{offdiag}}\left(3\right),\dots ,{\mathbf{offdiag}}\left(n\right)$, for ${\mathbf{uplo}}=\text{'U'}$. See Section 9 for further details.
6: $\mathbf{ipiv}\left({\mathbf{n}}\right)$Integer array Output
On exit: gives the permutation information of the factorization. The entries of ipiv are either positive, indicating a $1×1$ pivot block, or pairs of negative entries, indicating a $2×2$ pivot block.
${\mathbf{ipiv}}\left(i\right)=k>0$
The $i$th and $k$th rows and columns of $A$ were interchanged and ${d}_{ii}$ is a $1×1$ block.
${\mathbf{ipiv}}\left(i\right)=-k<0$ and ${\mathbf{ipiv}}\left(i+1\right)=-\ell <0$
The $i$th and $k$th rows and columns, and the $i+1$st and $\ell$th rows and columns, were interchanged and $D$ has the $2×2$ block:
 $( dii di+1,i di+1,i di+1,i+1 )$
• If ${\mathbf{uplo}}=\text{'U'}$, ${d}_{i+1,i}$ is stored in ${\mathbf{offdiag}}\left(i+1\right)$. The interchanges were made in the order $i={\mathbf{n}},{\mathbf{n}}-1,\dots ,2$.
• If ${\mathbf{uplo}}=\text{'L'}$, ${d}_{i+1,i}$ is stored in ${\mathbf{offdiag}}\left(i\right)$. The interchanges were made in the order $i=1,2,\dots ,{\mathbf{n}}-1$.
7: $\mathbf{delta}$Real (Kind=nag_wp) Input
On entry: the value of $\delta$.
Constraint: ${\mathbf{delta}}\ge 0.0$.
8: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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{uplo}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{uplo}}=\text{'U'}$ or $\text{'L'}$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}>0$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{lda}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{lda}}\ge {\mathbf{n}}$.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{delta}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{delta}}\ge 0.0$.
${\mathbf{ifail}}=5$
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

If ${\mathbf{uplo}}=\text{'L'}$, the computed factors $L$ and $D$ are the exact factors not of ${P}^{\mathrm{T}}\left(A+E\right)P$ but of $P\left(A+E+F\right){P}^{\mathrm{T}}$, where
 $‖F‖2 ≤ c(n) ε ‖A+E‖2 ≤ c(n) ε ‖L‖2 ‖D‖2 ‖LT‖2 ,$
$c\left(n\right)$ is a modest linear function of $n$, and $\epsilon$ is the machine precision.
If ${\mathbf{uplo}}=\text{'U'}$, a similar statement holds for the computed factors $U$ and $D$.

## 8Parallelism and Performance

f01mdf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
f01mdf 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.

The elements of the main diagonal of $D$ overwrite the corresponding elements of the main diagonal of $A$; the $n-1$ elements of the subdiagonal (and superdiagonal, by symmetry) elements of $D$ are stored in the array offdiag. If ${\mathbf{uplo}}=\text{'L'}$, then these are stored in ${\mathbf{offdiag}}\left(1\right),\dots ,{\mathbf{offdiag}}\left(n-1\right)$ that is ${d}_{i+1,i}$, for $i=1,\dots ,n-1$ is stored in ${\mathbf{offdiag}}\left(i\right)$; otherwise, they are stored in ${\mathbf{offdiag}}\left(2\right),\dots ,{\mathbf{offdiag}}\left(n\right)$, with ${d}_{i+1,i}$ stored in ${\mathbf{offdiag}}\left(i+1\right)$.
The unit diagonal elements of $U$ or $L$ are not stored. The remaining elements of $U$ or $L$ are stored explicitly in either the strictly upper or strictly lower triangular part of the array a, respectively.
The total number of floating-point operations is approximately $\frac{1}{3}{n}^{3}$. The searching overhead for rook pivoting used by the algorithm is between $\mathit{O}\left({n}^{2}\right)$ and $\mathit{O}\left({n}^{3}\right)$ comparisons. Experimental evidence suggests $\mathit{O}\left({n}^{2}\right)$ comparisons are usual, see Ashcraft et al. (1998).
All of the entries of the triangular matrix $L$ or $U$ are bounded above (by approximately $2.78$), and, therefore, the norm of the matrix itself is also bounded.
The exact size of the perturbation matrix $E$ cannot be predicted a priori. However, the algorithm attempts to ensure that it is not much greater than the minimum perturbation $\Delta A$ such that $A+\Delta A$ has the minimum eigenvalue $\delta$. In particular, it should be zero when $A$ is positive definite and $\delta =0$. If ${\mathbf{uplo}}=\text{'L'}$, then in general it can be shown that
 $‖E‖2 ≤ λmax(LLT) (δ- λmin(A) λmin(LLT) ) ,$
where ${\lambda }_{\text{max}}$ and ${\lambda }_{\text{min}}$ denote the largest and smallest eigenvalues of the matrix in question. A similar result holds if ${\mathbf{uplo}}=\text{'U'}$.

## 10Example

This example computes the modified Cholesky factorization $A+E=PLD{L}^{\mathrm{T}}{P}^{\mathrm{T}}$, for the indefinite matrix $A$, where
 $A= ( 0.9649 0.1419 0.0357 0.3922 0.0462 0.1419 0.4218 0.8491 0.6555 0.0971 0.0357 0.8491 0.9340 0.1712 0.8235 0.3922 0.6555 0.1712 0.7060 0.6948 0.0462 0.0971 0.8235 0.6948 0.3171 ) .$
The output is then passed to f01mef to explicitly form the matrix $A+E$ and the norm of $E$ is computed.

### 10.1Program Text

Program Text (f01mdfe.f90)

### 10.2Program Data

Program Data (f01mdfe.d)

### 10.3Program Results

Program Results (f01mdfe.r)