﻿ f07fb Method
f07fb 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 and $X$ and $B$ are $n$ by $r$ matrices. Error bounds on the solution and a condition estimate are also provided.

# Syntax

C#
```public static void f07fb(
string fact,
string uplo,
int n,
int nrhs,
double[,] a,
double[,] af,
ref string equed,
double[] s,
double[,] b,
double[,] x,
out double rcond,
double[] ferr,
double[] berr,
out int info
)```
Visual Basic
```Public Shared Sub f07fb ( _
fact As String, _
uplo As String, _
n As Integer, _
nrhs As Integer, _
a As Double(,), _
af As Double(,), _
ByRef equed As String, _
s As Double(), _
b As Double(,), _
x As Double(,), _
<OutAttribute> ByRef rcond As Double, _
ferr As Double(), _
berr As Double(), _
<OutAttribute> ByRef info As Integer _
)```
Visual C++
```public:
static void f07fb(
String^ fact,
String^ uplo,
int n,
int nrhs,
array<double,2>^ a,
array<double,2>^ af,
String^% equed,
array<double>^ s,
array<double,2>^ b,
array<double,2>^ x,
[OutAttribute] double% rcond,
array<double>^ ferr,
array<double>^ berr,
[OutAttribute] int% info
)```
F#
```static member f07fb :
fact : string *
uplo : string *
n : int *
nrhs : int *
a : float[,] *
af : float[,] *
equed : string byref *
s : float[] *
b : float[,] *
x : float[,] *
rcond : float byref *
ferr : float[] *
berr : float[] *
info : int byref -> unit
```

#### Parameters

fact
Type: System..::..String
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}}=\text{"F"}$
af contains the factorized form of $A$. If ${\mathbf{equed}}=\text{"Y"}$, the matrix $A$ has been equilibrated with scaling factors given by s. a and af will not be modified.
${\mathbf{fact}}=\text{"N"}$
The matrix $A$ will be copied to af and factorized.
${\mathbf{fact}}=\text{"E"}$
The matrix $A$ will be equilibrated if necessary, then copied to af and factorized.
Constraint: ${\mathbf{fact}}=\text{"F"}$, $\text{"N"}$ or $\text{"E"}$.
uplo
Type: System..::..String
On entry: if ${\mathbf{uplo}}=\text{"U"}$, the upper triangle of $A$ is stored.
If ${\mathbf{uplo}}=\text{"L"}$, the lower triangle of $A$ is stored.
Constraint: ${\mathbf{uplo}}=\text{"U"}$ or $\text{"L"}$.
n
Type: System..::..Int32
On entry: $n$, the number of linear equations, i.e., the order of the matrix $A$.
Constraint: ${\mathbf{n}}\ge 0$.
nrhs
Type: System..::..Int32
On entry: $r$, the number of right-hand sides, i.e., the number of columns of the matrix $B$.
Constraint: ${\mathbf{nrhs}}\ge 0$.
a
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
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$ by $n$ symmetric matrix $A$.
If ${\mathbf{fact}}=\text{"F"}$ and ${\mathbf{equed}}=\text{"Y"}$, a must have been equilibrated by the scaling factor in s as ${D}_{S}A{D}_{S}$.
• 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: if ${\mathbf{fact}}=\text{"F"}$ or $\text{"N"}$, or if ${\mathbf{fact}}=\text{"E"}$ and ${\mathbf{equed}}=\text{"N"}$, a is not modified.
If ${\mathbf{fact}}=\text{"E"}$ and ${\mathbf{equed}}=\text{"Y"}$, a is overwritten by ${D}_{S}A{D}_{S}$.
af
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
Note: the second dimension of the array af must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
On entry: if ${\mathbf{fact}}=\text{"F"}$, af 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 a. If ${\mathbf{equed}}\ne \text{"N"}$, af is the factorized form of the equilibrated matrix ${D}_{S}A{D}_{S}$.
On exit: if ${\mathbf{fact}}=\text{"N"}$, af 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}}=\text{"E"}$, af 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 a for the form of the equilibrated matrix).
equed
Type: System..::..String%
On entry: if ${\mathbf{fact}}=\text{"N"}$ or $\text{"E"}$, equed need not be set.
If ${\mathbf{fact}}=\text{"F"}$, equed must specify the form of the equilibration that was performed as follows:
• if ${\mathbf{equed}}=\text{"N"}$, no equilibration;
• if ${\mathbf{equed}}=\text{"Y"}$, equilibration was performed, i.e., $A$ has been replaced by ${D}_{S}A{D}_{S}$.
On exit: if ${\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.
Constraint: if ${\mathbf{fact}}=\text{"F"}$, ${\mathbf{equed}}=\text{"N"}$ or $\text{"Y"}$.
s
Type: array<System..::..Double>[]()[][]
An array of size [dim1]
Note: the dimension 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}}=\text{"N"}$ or $\text{"E"}$, s need not be set.
If ${\mathbf{fact}}=\text{"F"}$ and ${\mathbf{equed}}=\text{"Y"}$, s must contain the scale factors, ${D}_{S}$, for $A$; each element of s must be positive.
On exit: if ${\mathbf{fact}}=\text{"F"}$, s is unchanged from entry.
Otherwise, if no constraints are violated and ${\mathbf{equed}}=\text{"Y"}$, s contains the scale factors, ${D}_{S}$, for $A$; each element of s is positive.
b
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
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 $r$ right-hand side matrix $B$.
On exit: if ${\mathbf{equed}}=\text{"N"}$, b is not modified.
If ${\mathbf{equed}}=\text{"Y"}$, b is overwritten by ${D}_{S}B$.
x
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
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 exit: if ${\mathbf{info}}={0}$ or ${\mathbf{n}}{+}{1}$, 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}}=\text{"Y"}$, and the solution to the equilibrated system is ${D}_{S}^{-1}X$.
rcond
Type: System..::..Double%
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)$.
ferr
Type: array<System..::..Double>[]()[][]
An array of size [nrhs]
On exit: if ${\mathbf{info}}={0}$ or ${\mathbf{n}}{+}{1}$, 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.
berr
Type: array<System..::..Double>[]()[][]
An array of size [nrhs]
On exit: if ${\mathbf{info}}={0}$ or ${\mathbf{n}}{+}{1}$, 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).
info
Type: System..::..Int32%
On exit: ${\mathbf{info}}=0$ unless the method detects an error (see [Error Indicators and Warnings]).

# Description

f07fb performs the following steps:
1. If ${\mathbf{fact}}=\text{"E"}$, real diagonal scaling factors, ${D}_{S}$, are computed to equilibrate the system:
 $DSADSDS-1X=DSB.$
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}}=\text{"N"}$ or $\text{"E"}$, the Cholesky decomposition is used to factor the matrix $A$ (after equilibration if ${\mathbf{fact}}=\text{"E"}$) as $A={U}^{\mathrm{T}}U$ if ${\mathbf{uplo}}=\text{"U"}$ or $A=L{L}^{\mathrm{T}}$ if ${\mathbf{uplo}}=\text{"L"}$, 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 method returns with ${\mathbf{info}}=i$. 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, ${\mathbf{info}}={\mathbf{n}}{+}{1}$ is returned as a warning, but the method 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.

# 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

# Error Indicators and Warnings

Some error messages may refer to parameters that are dropped from this interface (LDA, LDAF, LDB, LDX) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
${\mathbf{info}}<0$
If ${\mathbf{info}}=-i$, argument $i$ had an illegal value. An explanatory message is output, and execution of the program is terminated.
${\mathbf{info}}>0 \text{and} {\mathbf{info}}\le {\mathbf{n}}$
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.
${\mathbf{info}}={\mathbf{n}}+1$
$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.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-4000$
Invalid dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# 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}}=\text{"U"}$, $\left|E\right|\le c\left(n\right)\epsilon \left|{U}^{\mathrm{T}}\right|\left|U\right|$;
• if ${\mathbf{uplo}}=\text{"L"}$, $\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^∞≤wccondA,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.

# Parallelism and Performance

None.

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 method is f07fp.

# Example

This example solves the equations
 $AX=B,$
where $A$ is the symmetric positive definite matrix
 $A=4.16-3.120.56-0.10-3.125.03-0.831.180.56-0.830.760.34-0.101.180.341.18$
and
 $B=8.708.30-13.352.131.891.61-4.145.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.

Example program (C#): f07fbe.cs

Example program data: f07fbe.d

Example program results: f07fbe.r