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_lapack_dppsvx (f07gb)

## Purpose

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

## Syntax

[ap, afp, equed, s, b, x, rcond, ferr, berr, info] = f07gb(fact, uplo, ap, afp, equed, s, b, 'n', n, 'nrhs_p', nrhs_p)
[ap, afp, equed, s, b, x, rcond, ferr, berr, info] = nag_lapack_dppsvx(fact, uplo, ap, afp, equed, s, b, 'n', n, 'nrhs_p', nrhs_p)

## Description

nag_lapack_dppsvx (f07gb) performs the following steps:
1. If fact = 'E'${\mathbf{fact}}=\text{'E'}$, real diagonal scaling factors, DS ${D}_{S}$, are computed to equilibrate the system:
 (DSADS) (DS − 1X) = DS B . $( DS A DS ) ( DS-1 X ) = DS B .$
Whether or not the system will be equilibrated depends on the scaling of the matrix A$A$, but if equilibration is used, A$A$ is overwritten by DS A DS ${D}_{S}A{D}_{S}$ and B$B$ by DS B${D}_{S}B$.
2. If fact = 'N'${\mathbf{fact}}=\text{'N'}$ or 'E'$\text{'E'}$, the Cholesky decomposition is used to factor the matrix A$A$ (after equilibration if fact = 'E'${\mathbf{fact}}=\text{'E'}$) as A = UTU$A={U}^{\mathrm{T}}U$ if uplo = 'U'${\mathbf{uplo}}=\text{'U'}$ or A = LLT$A=L{L}^{\mathrm{T}}$ if uplo = 'L'${\mathbf{uplo}}=\text{'L'}$, where U$U$ is an upper triangular matrix and L$L$ is a lower triangular matrix.
3. If the leading i$i$ by i$i$ principal minor of A$A$ is not positive definite, then the function returns with info = i${\mathbf{info}}=i$. Otherwise, the factored form of A$A$ is used to estimate the condition number of the matrix A$A$. If the reciprocal of the condition number is less than machine precision, infon + 1${\mathbf{info}}\ge {\mathbf{n}}+1$ is returned as a warning, but the function still goes on to solve for X$X$ and compute error bounds as described below.
4. The system of equations is solved for X$X$ using the factored form of A$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$X$ is premultiplied by DS ${D}_{S}$ so that it solves the original system before equilibration.

## 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

## Parameters

### Compulsory Input Parameters

1:     fact – string (length ≥ 1)
Specifies whether or not the factorized form of the matrix A$A$ is supplied on entry, and if not, whether the matrix A$A$ should be equilibrated before it is factorized.
fact = 'F'${\mathbf{fact}}=\text{'F'}$
afp contains the factorized form of A$A$. If equed = 'Y'${\mathbf{equed}}=\text{'Y'}$, the matrix A$A$ has been equilibrated with scaling factors given by s. ap and afp will not be modified.
fact = 'N'${\mathbf{fact}}=\text{'N'}$
The matrix A$A$ will be copied to afp and factorized.
fact = 'E'${\mathbf{fact}}=\text{'E'}$
The matrix A$A$ will be equilibrated if necessary, then copied to afp and factorized.
Constraint: fact = 'F'${\mathbf{fact}}=\text{'F'}$, 'N'$\text{'N'}$ or 'E'$\text{'E'}$.
2:     uplo – string (length ≥ 1)
If uplo = 'U'${\mathbf{uplo}}=\text{'U'}$, the upper triangle of A$A$ is stored.
If uplo = 'L'${\mathbf{uplo}}=\text{'L'}$, the lower triangle of A$A$ is stored.
Constraint: uplo = 'U'${\mathbf{uplo}}=\text{'U'}$ or 'L'$\text{'L'}$.
3:     ap( : $:$) – double array
Note: the dimension of the array ap must be at least max (1,n × (n + 1) / 2)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×\left({\mathbf{n}}+1\right)/2\right)$.
If fact = 'F'${\mathbf{fact}}=\text{'F'}$ and equed = 'Y'${\mathbf{equed}}=\text{'Y'}$, ap must contain the equilibrated matrix DSADS${D}_{S}A{D}_{S}$; otherwise, ap must contain the n$n$ by n$n$ symmetric matrix A$A$, packed by columns.
More precisely,
• if uplo = 'U'${\mathbf{uplo}}=\text{'U'}$, the upper triangle of A$A$ must be stored with element Aij${A}_{ij}$ in ap(i + j(j1) / 2)${\mathbf{ap}}\left(i+j\left(j-1\right)/2\right)$ for ij$i\le j$;
• if uplo = 'L'${\mathbf{uplo}}=\text{'L'}$, the lower triangle of A$A$ must be stored with element Aij${A}_{ij}$ in ap(i + (2nj)(j1) / 2)${\mathbf{ap}}\left(i+\left(2n-j\right)\left(j-1\right)/2\right)$ for ij$i\ge j$.
4:     afp( : $:$) – double array
Note: the dimension of the array afp must be at least max (1,n × (n + 1) / 2)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×\left({\mathbf{n}}+1\right)/2\right)$.
If fact = 'F'${\mathbf{fact}}=\text{'F'}$, afp contains the triangular factor U$U$ or L$L$ from the Cholesky factorization A = UTU$A={U}^{\mathrm{T}}U$ or A = LLT$A=L{L}^{\mathrm{T}}$, in the same storage format as ap. If equed = 'Y'${\mathbf{equed}}=\text{'Y'}$, afp is the factorized form of the equilibrated matrix DSADS${D}_{S}A{D}_{S}$.
5:     equed – string (length ≥ 1)
If fact = 'N'${\mathbf{fact}}=\text{'N'}$ or 'E'$\text{'E'}$, equed need not be set.
If fact = 'F'${\mathbf{fact}}=\text{'F'}$, equed must specify the form of the equilibration that was performed as follows:
• if equed = 'N'${\mathbf{equed}}=\text{'N'}$, no equilibration;
• if equed = 'Y'${\mathbf{equed}}=\text{'Y'}$, equilibration was performed, i.e., A$A$ has been replaced by DSADS${D}_{S}A{D}_{S}$.
Constraint: if fact = 'F'${\mathbf{fact}}=\text{'F'}$, equed = 'N'${\mathbf{equed}}=\text{'N'}$ or 'Y'$\text{'Y'}$.
6:     s( : $:$) – double array
Note: the dimension of the array s must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
If fact = 'N'${\mathbf{fact}}=\text{'N'}$ or 'E'$\text{'E'}$, s need not be set.
If fact = 'F'${\mathbf{fact}}=\text{'F'}$ and equed = 'Y'${\mathbf{equed}}=\text{'Y'}$, s must contain the scale factors, DS${D}_{S}$, for A$A$; each element of s must be positive.
7:     b(ldb, : $:$) – double array
The first dimension of the array b must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The second dimension of the array must be at least max (1,nrhs)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nrhs}}\right)$
The n$n$ by r$r$ right-hand side matrix B$B$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The first dimension of the array b The dimension of the array s.
n$n$, the number of linear equations, i.e., the order of the matrix A$A$.
Constraint: n0${\mathbf{n}}\ge 0$.
2:     nrhs_p – int64int32nag_int scalar
Default: The second dimension of the array b.
r$r$, the number of right-hand sides, i.e., the number of columns of the matrix B$B$.
Constraint: nrhs0${\mathbf{nrhs}}\ge 0$.

### Input Parameters Omitted from the MATLAB Interface

ldb ldx work iwork

### Output Parameters

1:     ap( : $:$) – double array
Note: the dimension of the array ap must be at least max (1,n × (n + 1) / 2)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×\left({\mathbf{n}}+1\right)/2\right)$.
If fact = 'F'${\mathbf{fact}}=\text{'F'}$ or 'N'$\text{'N'}$, or if fact = 'E'${\mathbf{fact}}=\text{'E'}$ and equed = 'N'${\mathbf{equed}}=\text{'N'}$, ap is not modified.
If fact = 'E'${\mathbf{fact}}=\text{'E'}$ and equed = 'Y'${\mathbf{equed}}=\text{'Y'}$, ap stores DSADS${D}_{S}A{D}_{S}$.
2:     afp( : $:$) – double array
Note: the dimension of the array afp must be at least max (1,n × (n + 1) / 2)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×\left({\mathbf{n}}+1\right)/2\right)$.
If fact = 'N'${\mathbf{fact}}=\text{'N'}$ or if fact = 'E'${\mathbf{fact}}=\text{'E'}$ and equed = 'N'${\mathbf{equed}}=\text{'N'}$, afp returns the triangular factor U$U$ or L$L$ from the Cholesky factorization A = UTU$A={U}^{\mathrm{T}}U$ or A = LLT$A=L{L}^{\mathrm{T}}$ of the original matrix A$A$.
If fact = 'E'${\mathbf{fact}}=\text{'E'}$ and equed = 'Y'${\mathbf{equed}}=\text{'Y'}$, afp returns the triangular factor U$U$ or L$L$ from the Cholesky factorization A = UTU$A={U}^{\mathrm{T}}U$ or A = LLT$A=L{L}^{\mathrm{T}}$ of the equilibrated matrix A$A$ (see the description of ap for the form of the equilibrated matrix).
3:     equed – string (length ≥ 1)
If fact = 'F'${\mathbf{fact}}=\text{'F'}$, equed is unchanged from entry.
Otherwise, if no constraints are violated, equed specifies the form of the equilibration that was performed as specified above.
4:     s( : $:$) – double array
Note: the dimension of the array s must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
If fact = 'F'${\mathbf{fact}}=\text{'F'}$, s is unchanged from entry.
Otherwise, if no constraints are violated and equed = 'Y'${\mathbf{equed}}=\text{'Y'}$, s contains the scale factors, DS${D}_{S}$, for A$A$; each element of s is positive.
5:     b(ldb, : $:$) – double array
The first dimension of the array b will be max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The second dimension of the array will be max (1,nrhs)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nrhs}}\right)$
ldbmax (1,n)$\mathit{ldb}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
If equed = 'N'${\mathbf{equed}}=\text{'N'}$, b is not modified.
If equed = 'Y'${\mathbf{equed}}=\text{'Y'}$, b stores DSB${D}_{S}B$.
6:     x(ldx, : $:$) – double array
The first dimension of the array x will be max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The second dimension of the array will be max (1,nrhs)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{nrhs}}\right)$
ldxmax (1,n)$\mathit{ldx}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
If ${\mathbf{INFO}}={\mathbf{0}}$ or n + 1$\mathbf{n}+{\mathbf{1}}$, the n$n$ by r$r$ solution matrix X$X$ to the original system of equations. Note that the arrays A$A$ and B$B$ are modified on exit if equed = 'Y'${\mathbf{equed}}=\text{'Y'}$, and the solution to the equilibrated system is DS1X${D}_{S}^{-1}X$.
7:     rcond – double scalar
If no constraints are violated, an estimate of the reciprocal condition number of the matrix A$A$ (after equilibration if that is performed), computed as rcond = 1.0 / (A1A11)${\mathbf{rcond}}=1.0/\left({‖A‖}_{1}{‖{A}^{-1}‖}_{1}\right)$.
8:     ferr(nrhs_p) – double array
If ${\mathbf{INFO}}={\mathbf{0}}$ or n + 1$\mathbf{n}+{\mathbf{1}}$, an estimate of the forward error bound for each computed solution vector, such that jxj / xjferr(j)${‖{\stackrel{^}{x}}_{j}-{x}_{j}‖}_{\infty }/{‖{x}_{j}‖}_{\infty }\le {\mathbf{ferr}}\left(j\right)$ where j${\stackrel{^}{x}}_{j}$ is the j$j$th column of the computed solution returned in the array x and xj${x}_{j}$ is the corresponding column of the exact solution X$X$. The estimate is as reliable as the estimate for rcond, and is almost always a slight overestimate of the true error.
9:     berr(nrhs_p) – double array
If ${\mathbf{INFO}}={\mathbf{0}}$ or n + 1$\mathbf{n}+{\mathbf{1}}$, an estimate of the component-wise relative backward error of each computed solution vector j${\stackrel{^}{x}}_{j}$ (i.e., the smallest relative change in any element of A$A$ or B$B$ that makes j${\stackrel{^}{x}}_{j}$ an exact solution).
10:   info – int64int32nag_int scalar
info = 0${\mathbf{info}}=0$ unless the function detects an error (see Section [Error Indicators and Warnings]).

## Error Indicators and Warnings

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

info = i${\mathbf{info}}=-i$
If info = i${\mathbf{info}}=-i$, parameter i$i$ had an illegal value on entry. The parameters are numbered as follows:
1: fact, 2: uplo, 3: n, 4: nrhs_p, 5: ap, 6: afp, 7: equed, 8: s, 9: b, 10: ldb, 11: x, 12: ldx, 13: rcond, 14: ferr, 15: berr, 16: work, 17: iwork, 18: info.
It is possible that info refers to a parameter that is omitted from the MATLAB interface. This usually indicates that an error in one of the other input parameters has caused an incorrect value to be inferred.
INFO > 0andINFON${\mathbf{INFO}}>0 \text{and} {\mathbf{INFO}}\le {\mathbf{N}}$
If info = i${\mathbf{info}}=i$ and in$i\le {\mathbf{n}}$, the leading minor of order i$i$ of A$A$ is not positive definite, so the factorization could not be completed, and the solution has not been computed. rcond = 0.0${\mathbf{rcond}}=0.0$ is returned.
W INFO = N + 1${\mathbf{INFO}}={\mathbf{N}}+1$
The triangular matrix U$U$ (or L$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.

## Accuracy

For each right-hand side vector b$b$, the computed solution x$x$ is the exact solution of a perturbed system of equations (A + E)x = b$\left(A+E\right)x=b$, where
• if uplo = 'U'${\mathbf{uplo}}=\text{'U'}$, |E|c(n)ε|UT||U|$|E|\le c\left(n\right)\epsilon |{U}^{\mathrm{T}}||U|$;
• if uplo = 'L'${\mathbf{uplo}}=\text{'L'}$, |E|c(n)ε|L||LT|$|E|\le c\left(n\right)\epsilon |L||{L}^{\mathrm{T}}|$,
c(n)$c\left(n\right)$ is a modest linear function of n$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$x$ satisfies a forward error bound of the form
 ( ‖x − x̂‖∞ )/( ‖x̂‖∞ ) ≤ wc cond(A,x̂,b) , $‖x-x^‖∞ ‖x^‖∞ ≤ wc cond(A,x^,b) ,$
where cond(A,,b) = |A1|(|A||| + |b|) / cond(A) = |A1||A|κ (A) $\mathrm{cond}\left(A,\stackrel{^}{x},b\right)={‖|{A}^{-1}|\left(|A||\stackrel{^}{x}|+|b|\right)‖}_{\infty }/{‖\stackrel{^}{x}‖}_{\infty }\le \mathrm{cond}\left(A\right)={‖|{A}^{-1}||A|‖}_{\infty }\le {\kappa }_{\infty }\left(A\right)$. If $\stackrel{^}{x}$ is the j $j$th column of X $X$, then wc ${w}_{c}$ is returned in berr(j) ${\mathbf{berr}}\left(j\right)$ and a bound on x / ${‖x-\stackrel{^}{x}‖}_{\infty }/{‖\stackrel{^}{x}‖}_{\infty }$ is returned in ferr(j) ${\mathbf{ferr}}\left(j\right)$. See Section 4.4 of Anderson et al. (1999) for further details.

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

## Example

```function nag_lapack_dppsvx_example
fact = 'Equilibration';
uplo = 'U';
ap = [4.16;
-3.12;
5.03;
0.56;
-0.83;
0.76;
-0.1;
1.18;
0.34;
1.18];
afp = zeros(10,1);
equed = ' ';
s = zeros(4,1);
b = [8.7, 8.3;
-13.35, 2.13;
1.89, 1.61;
-4.14, 5];
[apOut, afpOut, equedOut, sOut, bOut, x, rcond, ferr, berr, info] = ...
nag_lapack_dppsvx(fact, uplo, ap, afp, equed, s, b)
```
```

apOut =

4.1600
-3.1200
5.0300
0.5600
-0.8300
0.7600
-0.1000
1.1800
0.3400
1.1800

afpOut =

2.0396
-1.5297
1.6401
0.2746
-0.2500
0.7887
-0.0490
0.6737
0.6617
0.5347

equedOut =

N

sOut =

0.4903
0.4459
1.1471
0.9206

bOut =

8.7000    8.3000
-13.3500    2.1300
1.8900    1.6100
-4.1400    5.0000

x =

1.0000    4.0000
-1.0000    3.0000
2.0000    2.0000
-3.0000    1.0000

rcond =

0.0103

ferr =

1.0e-13 *

0.2349
0.2307

berr =

1.0e-16 *

0.6653
0.7892

info =

0

```
```function f07gb_example
fact = 'Equilibration';
uplo = 'U';
ap = [4.16;
-3.12;
5.03;
0.56;
-0.83;
0.76;
-0.1;
1.18;
0.34;
1.18];
afp = zeros(10,1);
equed = ' ';
s = zeros(4,1);
b = [8.7, 8.3;
-13.35, 2.13;
1.89, 1.61;
-4.14, 5];
[apOut, afpOut, equedOut, sOut, bOut, x, rcond, ferr, berr, info] = ...
f07gb(fact, uplo, ap, afp, equed, s, b)
```
```

apOut =

4.1600
-3.1200
5.0300
0.5600
-0.8300
0.7600
-0.1000
1.1800
0.3400
1.1800

afpOut =

2.0396
-1.5297
1.6401
0.2746
-0.2500
0.7887
-0.0490
0.6737
0.6617
0.5347

equedOut =

N

sOut =

0.4903
0.4459
1.1471
0.9206

bOut =

8.7000    8.3000
-13.3500    2.1300
1.8900    1.6100
-4.1400    5.0000

x =

1.0000    4.0000
-1.0000    3.0000
2.0000    2.0000
-3.0000    1.0000

rcond =

0.0103

ferr =

1.0e-13 *

0.2349
0.2307

berr =

1.0e-16 *

0.6653
0.7892

info =

0

```