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_linsys_real_square_solve_ref (f04ae)

## Purpose

nag_linsys_real_square_solve_ref (f04ae) calculates the accurate solution of a set of real linear equations with multiple right-hand sides using an LU$LU$ factorization with partial pivoting, and iterative refinement.

## Syntax

[c, aa, bb, ifail] = f04ae(a, b, 'n', n, 'm', m)
[c, aa, bb, ifail] = nag_linsys_real_square_solve_ref(a, b, 'n', n, 'm', m)

## Description

Given a set of real linear equations AX = B$AX=B$, the function first computes an LU$LU$ factorization of A$A$ with partial pivoting, PA = LU$PA=LU$, where P$P$ is a permutation matrix, L$L$ is lower triangular and U$U$ is unit upper triangular. An approximation to X$X$ is found by forward and backward substitution. The residual matrix R = BAX$R=B-AX$ is then calculated using additional precision, and a correction D$D$ to X$X$ is found by solving LUD = PR$LUD=PR$. X$X$ is replaced by X + D$X+D$ and this iterative refinement of the solution is repeated until full machine accuracy has been obtained.

## References

Wilkinson J H and Reinsch C (1971) Handbook for Automatic Computation II, Linear Algebra Springer–Verlag

## Parameters

### Compulsory Input Parameters

1:     a(lda, : $:$) – double array
The first dimension of the array a 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,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The n$n$ by n$n$ matrix A$A$.
2:     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,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$
The n$n$ by m$m$ right-hand side matrix B$B$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The first dimension of the arrays a, b The second dimension of the array a.
n$n$, the order of the matrix A$A$.
Constraint: n0${\mathbf{n}}\ge 0$.
2:     m – int64int32nag_int scalar
Default: The second dimension of the array b.
m$m$, the number of right-hand sides.
Constraint: m0${\mathbf{m}}\ge 0$.

### Input Parameters Omitted from the MATLAB Interface

lda ldb ldc wkspce ldaa ldbb

### Output Parameters

1:     c(ldc, : $:$) – double array
The first dimension of the array c 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,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$
ldcmax (1,n)$\mathit{ldc}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The n$n$ by m$m$ solution matrix X$X$.
2:     aa(ldaa, : $:$) – double array
The first dimension of the array aa 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,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
ldaamax (1,n)$\mathit{ldaa}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The triangular factors L$L$ and U$U$, except that the unit diagonal elements of U$U$ are not stored.
3:     bb(ldbb, : $:$) – double array
The first dimension of the array bb 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,m)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{m}}\right)$
ldbbmax (1,n)$\mathit{ldbb}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
The final n$n$ by m$m$ residual matrix R = BAX$R=B-AX$.
4:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
The matrix A$A$ is singular, possibly due to rounding errors.
ifail = 2${\mathbf{ifail}}=2$
Iterative refinement fails to improve the solution, i.e., the matrix A$A$ is too ill-conditioned.
ifail = 3${\mathbf{ifail}}=3$
 On entry, n < 0${\mathbf{n}}<0$, or m < 0${\mathbf{m}}<0$, or lda < max (1,n)$\mathit{lda}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$, or ldb < max (1,n)$\mathit{ldb}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$, or ldc < max (1,n)$\mathit{ldc}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$, or ldaa < max (1,n)$\mathit{ldaa}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$, or ldbb < max (1,n)$\mathit{ldbb}<\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.

## Accuracy

The computed solutions should be correct to full machine accuracy. For a detailed error analysis see page 107 of Wilkinson and Reinsch (1971).

The time taken by nag_linsys_real_square_solve_ref (f04ae) is approximately proportional to n3${n}^{3}$.
If there is only one right-hand side, it is simpler to use nag_linsys_real_square_solve_1rhs (f04at).

## Example

```function nag_linsys_real_square_solve_ref_example
a = [33, 16, 72;
-24, -10, -57;
-8, -4, -17];
b = [-359;
281;
85];
[c, aa, bb, ifail] = nag_linsys_real_square_solve_ref(a, b)
```
```

c =

1
-2
-5

aa =

-8.0000    0.5000    2.1250
-24.0000    2.0000   -3.0000
33.0000   -0.5000    0.3750

bb =

0
0
0

ifail =

0

```
```function f04ae_example
a = [33, 16, 72;
-24, -10, -57;
-8, -4, -17];
b = [-359;
281;
85];
[c, aa, bb, ifail] = f04ae(a, b)
```
```

c =

1
-2
-5

aa =

-8.0000    0.5000    2.1250
-24.0000    2.0000   -3.0000
33.0000   -0.5000    0.3750

bb =

0
0
0

ifail =

0

```