f07 Chapter Contents
f07 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_dppsvx (f07gbc)

## 1  Purpose

nag_dppsvx (f07gbc) uses the Cholesky factorization
 $A=UTU or A=LLT$
to compute the solution to a real system of linear equations
 $AX=B ,$
where $A$ is an $n$ by $n$ symmetric positive definite matrix stored in packed format and $X$ and $B$ are $n$ by $r$ matrices. Error bounds on the solution and a condition estimate are also provided.

## 2  Specification

 #include #include
 void nag_dppsvx (Nag_OrderType order, Nag_FactoredFormType fact, Nag_UploType uplo, Integer n, Integer nrhs, double ap[], double afp[], Nag_EquilibrationType *equed, double s[], double b[], Integer pdb, double x[], Integer pdx, double *rcond, double ferr[], double berr[], NagError *fail)

## 3  Description

nag_dppsvx (f07gbc) performs the following steps:
1. If ${\mathbf{fact}}=\mathrm{Nag_EquilibrateAndFactor}$, real diagonal scaling factors, ${D}_{S}$, are computed to equilibrate the system:
 $DS A DS DS-1 X = DS B .$
Whether or not the system will be equilibrated depends on the scaling of the matrix $A$, but if equilibration is used, $A$ is overwritten by ${D}_{S}A{D}_{S}$ and $B$ by ${D}_{S}B$.
2. If ${\mathbf{fact}}=\mathrm{Nag_NotFactored}$ or $\mathrm{Nag_EquilibrateAndFactor}$, the Cholesky decomposition is used to factor the matrix $A$ (after equilibration if ${\mathbf{fact}}=\mathrm{Nag_EquilibrateAndFactor}$) as $A={U}^{\mathrm{T}}U$ if ${\mathbf{uplo}}=\mathrm{Nag_Upper}$ or $A=L{L}^{\mathrm{T}}$ if ${\mathbf{uplo}}=\mathrm{Nag_Lower}$, where $U$ is an upper triangular matrix and $L$ is a lower triangular matrix.
3. If the leading $i$ by $i$ principal minor of $A$ is not positive definite, then the function returns with ${\mathbf{fail}}\mathbf{.}\mathbf{errnum}=i$ and NE_MAT_NOT_POS_DEF. Otherwise, the factored form of $A$ is used to estimate the condition number of the matrix $A$. If the reciprocal of the condition number is less than machine precision, NE_SINGULAR_WP is returned as a warning, but the function still goes on to solve for $X$ and compute error bounds as described below.
4. The system of equations is solved for $X$ using the factored form of $A$.
5. Iterative refinement is applied to improve the computed solution matrix and to calculate error bounds and backward error estimates for it.
6. If equilibration was used, the matrix $X$ is premultiplied by ${D}_{S}$ so that it solves the original system before equilibration.

## 4  References

Anderson E, Bai Z, Bischof C, Blackford S, Demmel J, Dongarra J J, Du Croz J J, Greenbaum A, Hammarling S, McKenney A and Sorensen D (1999) LAPACK Users' Guide (3rd Edition) SIAM, Philadelphia http://www.netlib.org/lapack/lug
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
Higham N J (2002) Accuracy and Stability of Numerical Algorithms (2nd Edition) SIAM, Philadelphia

## 5  Arguments

1:     orderNag_OrderTypeInput
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by ${\mathbf{order}}=\mathrm{Nag_RowMajor}$. See Section 3.2.1.3 in the Essential Introduction for a more detailed explanation of the use of this argument.
Constraint: ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ or Nag_ColMajor.
2:     factNag_FactoredFormTypeInput
On entry: specifies whether or not the factorized form of the matrix $A$ is supplied on entry, and if not, whether the matrix $A$ should be equilibrated before it is factorized.
${\mathbf{fact}}=\mathrm{Nag_Factored}$
afp contains the factorized form of $A$. If ${\mathbf{equed}}=\mathrm{Nag_Equilibrated}$, the matrix $A$ has been equilibrated with scaling factors given by s. ap and afp will not be modified.
${\mathbf{fact}}=\mathrm{Nag_NotFactored}$
The matrix $A$ will be copied to afp and factorized.
${\mathbf{fact}}=\mathrm{Nag_EquilibrateAndFactor}$
The matrix $A$ will be equilibrated if necessary, then copied to afp and factorized.
Constraint: ${\mathbf{fact}}=\mathrm{Nag_Factored}$, $\mathrm{Nag_NotFactored}$ or $\mathrm{Nag_EquilibrateAndFactor}$.
3:     uploNag_UploTypeInput
On entry: if ${\mathbf{uplo}}=\mathrm{Nag_Upper}$, the upper triangle of $A$ is stored.
If ${\mathbf{uplo}}=\mathrm{Nag_Lower}$, the lower triangle of $A$ is stored.
Constraint: ${\mathbf{uplo}}=\mathrm{Nag_Upper}$ or $\mathrm{Nag_Lower}$.
4:     nIntegerInput
On entry: $n$, the number of linear equations, i.e., the order of the matrix $A$.
Constraint: ${\mathbf{n}}\ge 0$.
5:     nrhsIntegerInput
On entry: $r$, the number of right-hand sides, i.e., the number of columns of the matrix $B$.
Constraint: ${\mathbf{nrhs}}\ge 0$.
6:     ap[$\mathit{dim}$]doubleInput/Output
Note: the dimension, dim, of the array ap must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×\left({\mathbf{n}}+1\right)/2\right)$.
On entry: if ${\mathbf{fact}}=\mathrm{Nag_Factored}$ and ${\mathbf{equed}}=\mathrm{Nag_Equilibrated}$, ap must contain the equilibrated matrix ${D}_{S}A{D}_{S}$; otherwise, ap must contain the $n$ by $n$ symmetric matrix $A$, packed by rows or columns.
The storage of elements ${A}_{ij}$ depends on the order and uplo arguments as follows:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$ and ${\mathbf{uplo}}=\mathrm{Nag_Upper}$,
${A}_{ij}$ is stored in ${\mathbf{ap}}\left[\left(j-1\right)×j/2+i-1\right]$, for $i\le j$;
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$ and ${\mathbf{uplo}}=\mathrm{Nag_Lower}$,
${A}_{ij}$ is stored in ${\mathbf{ap}}\left[\left(2n-j\right)×\left(j-1\right)/2+i-1\right]$, for $i\ge j$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ and ${\mathbf{uplo}}=\mathrm{Nag_Upper}$,
${A}_{ij}$ is stored in ${\mathbf{ap}}\left[\left(2n-i\right)×\left(i-1\right)/2+j-1\right]$, for $i\le j$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ and ${\mathbf{uplo}}=\mathrm{Nag_Lower}$,
${A}_{ij}$ is stored in ${\mathbf{ap}}\left[\left(i-1\right)×i/2+j-1\right]$, for $i\ge j$.
On exit: if ${\mathbf{fact}}=\mathrm{Nag_Factored}$ or $\mathrm{Nag_NotFactored}$, or if ${\mathbf{fact}}=\mathrm{Nag_EquilibrateAndFactor}$ and ${\mathbf{equed}}=\mathrm{Nag_NoEquilibration}$, ap is not modified.
If ${\mathbf{fact}}=\mathrm{Nag_EquilibrateAndFactor}$ and ${\mathbf{equed}}=\mathrm{Nag_Equilibrated}$, ap is overwritten by ${D}_{S}A{D}_{S}$.
7:     afp[$\mathit{dim}$]doubleInput/Output
Note: the dimension, dim, of the array afp must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×\left({\mathbf{n}}+1\right)/2\right)$.
On entry: if ${\mathbf{fact}}=\mathrm{Nag_Factored}$, afp contains the triangular factor $U$ or $L$ from the Cholesky factorization $A={U}^{\mathrm{T}}U$ or $A=L{L}^{\mathrm{T}}$, in the same storage format as ap. If ${\mathbf{equed}}=\mathrm{Nag_Equilibrated}$, afp is the factorized form of the equilibrated matrix ${D}_{S}A{D}_{S}$.
On exit: if ${\mathbf{fact}}=\mathrm{Nag_NotFactored}$ or if ${\mathbf{fact}}=\mathrm{Nag_EquilibrateAndFactor}$ and ${\mathbf{equed}}=\mathrm{Nag_NoEquilibration}$, afp returns the triangular factor $U$ or $L$ from the Cholesky factorization $A={U}^{\mathrm{T}}U$ or $A=L{L}^{\mathrm{T}}$ of the original matrix $A$.
If ${\mathbf{fact}}=\mathrm{Nag_EquilibrateAndFactor}$ and ${\mathbf{equed}}=\mathrm{Nag_Equilibrated}$, afp returns the triangular factor $U$ or $L$ from the Cholesky factorization $A={U}^{\mathrm{T}}U$ or $A=L{L}^{\mathrm{T}}$ of the equilibrated matrix $A$ (see the description of ap for the form of the equilibrated matrix).
8:     equedNag_EquilibrationType*Input/Output
On entry: if ${\mathbf{fact}}=\mathrm{Nag_NotFactored}$ or $\mathrm{Nag_EquilibrateAndFactor}$, equed need not be set.
If ${\mathbf{fact}}=\mathrm{Nag_Factored}$, equed must specify the form of the equilibration that was performed as follows:
• if ${\mathbf{equed}}=\mathrm{Nag_NoEquilibration}$, no equilibration;
• if ${\mathbf{equed}}=\mathrm{Nag_Equilibrated}$, equilibration was performed, i.e., $A$ has been replaced by ${D}_{S}A{D}_{S}$.
On exit: if ${\mathbf{fact}}=\mathrm{Nag_Factored}$, equed is unchanged from entry.
Otherwise, if no constraints are violated, equed specifies the form of the equilibration that was performed as specified above.
Constraint: if ${\mathbf{fact}}=\mathrm{Nag_Factored}$, ${\mathbf{equed}}=\mathrm{Nag_NoEquilibration}$ or $\mathrm{Nag_Equilibrated}$.
9:     s[$\mathit{dim}$]doubleInput/Output
Note: the dimension, dim, of the array s must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry: if ${\mathbf{fact}}=\mathrm{Nag_NotFactored}$ or $\mathrm{Nag_EquilibrateAndFactor}$, s need not be set.
If ${\mathbf{fact}}=\mathrm{Nag_Factored}$ and ${\mathbf{equed}}=\mathrm{Nag_Equilibrated}$, s must contain the scale factors, ${D}_{S}$, for $A$; each element of s must be positive.
On exit: if ${\mathbf{fact}}=\mathrm{Nag_Factored}$, s is unchanged from entry.
Otherwise, if no constraints are violated and ${\mathbf{equed}}=\mathrm{Nag_Equilibrated}$, s contains the scale factors, ${D}_{S}$, for $A$; each element of s is positive.
10:   b[$\mathit{dim}$]doubleInput/Output
Note: the dimension, dim, of the array b must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdb}}×{\mathbf{nrhs}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×{\mathbf{pdb}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
The $\left(i,j\right)$th element of the matrix $B$ is stored in
• ${\mathbf{b}}\left[\left(j-1\right)×{\mathbf{pdb}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{b}}\left[\left(i-1\right)×{\mathbf{pdb}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: the $n$ by $r$ right-hand side matrix $B$.
On exit: if ${\mathbf{equed}}=\mathrm{Nag_NoEquilibration}$, b is not modified.
If ${\mathbf{equed}}=\mathrm{Nag_Equilibrated}$, b is overwritten by ${D}_{S}B$.
11:   pdbIntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array b.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$, ${\mathbf{pdb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pdb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nrhs}}\right)$.
12:   x[$\mathit{dim}$]doubleOutput
Note: the dimension, dim, of the array x must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdx}}×{\mathbf{nrhs}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×{\mathbf{pdx}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
The $\left(i,j\right)$th element of the matrix $X$ is stored in
• ${\mathbf{x}}\left[\left(j-1\right)×{\mathbf{pdx}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{x}}\left[\left(i-1\right)×{\mathbf{pdx}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On exit: if NE_NOERROR or NE_SINGULAR_WP, the $n$ by $r$ solution matrix $X$ to the original system of equations. Note that the arrays $A$ and $B$ are modified on exit if ${\mathbf{equed}}=\mathrm{Nag_Equilibrated}$, and the solution to the equilibrated system is ${D}_{S}^{-1}X$.
13:   pdxIntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array x.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$, ${\mathbf{pdx}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pdx}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nrhs}}\right)$.
14:   rconddouble *Output
On exit: if no constraints are violated, an estimate of the reciprocal condition number of the matrix $A$ (after equilibration if that is performed), computed as ${\mathbf{rcond}}=1.0/\left({‖A‖}_{1}{‖{A}^{-1}‖}_{1}\right)$.
15:   ferr[nrhs]doubleOutput
On exit: if NE_NOERROR or NE_SINGULAR_WP, an estimate of the forward error bound for each computed solution vector, such that ${‖{\stackrel{^}{x}}_{j}-{x}_{j}‖}_{\infty }/{‖{x}_{j}‖}_{\infty }\le {\mathbf{ferr}}\left[j-1\right]$ where ${\stackrel{^}{x}}_{j}$ is the $j$th column of the computed solution returned in the array x and ${x}_{j}$ is the corresponding column of the exact solution $X$. The estimate is as reliable as the estimate for rcond, and is almost always a slight overestimate of the true error.
16:   berr[nrhs]doubleOutput
On exit: if NE_NOERROR or NE_SINGULAR_WP, an estimate of the component-wise relative backward error of each computed solution vector ${\stackrel{^}{x}}_{j}$ (i.e., the smallest relative change in any element of $A$ or $B$ that makes ${\stackrel{^}{x}}_{j}$ an exact solution).
17:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INT
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{pdb}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdb}}>0$.
On entry, ${\mathbf{pdx}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdx}}>0$.
NE_INT_2
On entry, ${\mathbf{pdb}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry, ${\mathbf{pdb}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nrhs}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdb}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nrhs}}\right)$.
On entry, ${\mathbf{pdx}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdx}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry, ${\mathbf{pdx}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nrhs}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{pdx}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nrhs}}\right)$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_MAT_NOT_POS_DEF
The leading minor of order $〈\mathit{\text{value}}〉$ of $A$ is not positive definite, so the factorization could not be completed, and the solution has not been computed. ${\mathbf{rcond}}=0.0$ is returned.
NE_SINGULAR_WP
$U$ (or $L$) is nonsingular, but rcond is less than machine precision, meaning that the matrix is singular to working precision. Nevertheless, the solution and error bounds are computed because there are a number of situations where the computed solution can be more accurate than the value of rcond would suggest.

## 7  Accuracy

For each right-hand side vector $b$, the computed solution $x$ is the exact solution of a perturbed system of equations $\left(A+E\right)x=b$, where
• if ${\mathbf{uplo}}=\mathrm{Nag_Upper}$, $\left|E\right|\le c\left(n\right)\epsilon \left|{U}^{\mathrm{T}}\right|\left|U\right|$;
• if ${\mathbf{uplo}}=\mathrm{Nag_Lower}$, $\left|E\right|\le c\left(n\right)\epsilon \left|L\right|\left|{L}^{\mathrm{T}}\right|$,
$c\left(n\right)$ is a modest linear function of $n$, and $\epsilon$ is the machine precision. See Section 10.1 of Higham (2002) for further details.
If $\stackrel{^}{x}$ is the true solution, then the computed solution $x$ satisfies a forward error bound of the form
 $x-x^∞ x^∞ ≤ wc condA,x^,b ,$
where $\mathrm{cond}\left(A,\stackrel{^}{x},b\right)={‖\left|{A}^{-1}\right|\left(\left|A\right|\left|\stackrel{^}{x}\right|+\left|b\right|\right)‖}_{\infty }/{‖\stackrel{^}{x}‖}_{\infty }\le \mathrm{cond}\left(A\right)={‖\left|{A}^{-1}\right|\left|A\right|‖}_{\infty }\le {\kappa }_{\infty }\left(A\right)$. If $\stackrel{^}{x}$ is the $j$th column of $X$, then ${w}_{c}$ is returned in ${\mathbf{berr}}\left[j-1\right]$ and a bound on ${‖x-\stackrel{^}{x}‖}_{\infty }/{‖\stackrel{^}{x}‖}_{\infty }$ is returned in ${\mathbf{ferr}}\left[j-1\right]$. See Section 4.4 of Anderson et al. (1999) for further details.

## 8  Further Comments

The factorization of $A$ requires approximately $\frac{1}{3}{n}^{3}$ floating point operations.
For each right-hand side, computation of the backward error involves a minimum of $4{n}^{2}$ floating point operations. Each step of iterative refinement involves an additional $6{n}^{2}$ operations. 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 equations of the form $Ax=b$; the number is usually $4$ or $5$ and never more than $11$. Each solution involves approximately $2{n}^{2}$ operations.
The complex analogue of this function is nag_zppsvx (f07gpc).

## 9  Example

This example solves the equations
 $AX=B ,$
where $A$ is the symmetric positive definite matrix
 $A = 4.16 -3.12 0.56 -0.10 -3.12 5.03 -0.83 1.18 0.56 -0.83 0.76 0.34 -0.10 1.18 0.34 1.18$
and
 $B = 8.70 8.30 -13.35 2.13 1.89 1.61 -4.14 5.00 .$
Error estimates for the solutions, information on equilibration and an estimate of the reciprocal of the condition number of the scaled matrix $A$ are also output.

### 9.1  Program Text

Program Text (f07gbce.c)

### 9.2  Program Data

Program Data (f07gbce.d)

### 9.3  Program Results

Program Results (f07gbce.r)