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_fit_glin_linf (e02gc)

Purpose

nag_fit_glin_linf (e02gc) calculates an l${l}_{\infty }$ solution to an over-determined system of linear equations.

Syntax

[a, b, relerr, x, resmax, irank, iter, ifail] = e02gc(n, a, b, relerr, 'm', m, 'tol', tol)
[a, b, relerr, x, resmax, irank, iter, ifail] = nag_fit_glin_linf(n, a, b, relerr, 'm', m, 'tol', tol)

Description

Given a matrix A$A$ with m$m$ rows and n$n$ columns (mn)$\left(m\ge n\right)$ and a vector b$b$ with m$m$ elements, the function calculates an l${l}_{\infty }$ solution to the over-determined system of equations
 Ax = b. $Ax=b.$
That is to say, it calculates a vector x$x$, with n$n$ elements, which minimizes the l${l}_{\infty }$ norm of the residuals (the absolutely largest residual)
 r(x) = max |ri| 1 ≤ i ≤ m
$r(x) = max 1≤i≤m |ri|$
where the residuals ri${r}_{i}$ are given by
 n ri = bi − ∑ aijxj,  i = 1,2, … ,m. j = 1
$ri = bi - ∑ j=1n aij xj , i=1,2,…,m .$
Here aij${a}_{ij}$ is the element in row i$i$ and column j$j$ of A$A$, bi${b}_{i}$ is the i$i$th element of b$b$ and xj${x}_{j}$ the j$j$th element of x$x$. The matrix A$A$ need not be of full rank. The solution is not unique in this case, and may not be unique even if A$A$ is of full rank.
Alternatively, in applications where a complete minimization of the l${l}_{\infty }$ norm is not necessary, you may obtain an approximate solution, usually in shorter time, by giving an appropriate value to the parameter relerr.
Typically in applications to data fitting, data consisting of m$m$ points with coordinates (ti,yi)$\left({t}_{i},{y}_{i}\right)$ is to be approximated in the l${l}_{\infty }$ norm by a linear combination of known functions φj(t)${\varphi }_{j}\left(t\right)$,
 α1φ1(t) + α2φ2(t) + ⋯ + αnφn(t). $α1ϕ1(t)+α2ϕ2(t)+⋯+αnϕn(t).$
This is equivalent to finding an l${l}_{\infty }$ solution to the over-determined system of equations
 n ∑ φj(ti)αj = yi,  i = 1,2, … ,m. j = 1
$∑ j=1n ϕj (ti) αj = yi , i=1,2,…,m .$
Thus if, for each value of i$i$ and j$j$ the element aij${a}_{ij}$ of the matrix A$A$ above is set equal to the value of φj(ti)${\varphi }_{j}\left({t}_{i}\right)$ and bi${b}_{i}$ is set equal to yi${y}_{i}$, the solution vector x$x$ will contain the required values of the αj${\alpha }_{j}$. Note that the independent variable t$t$ above can, instead, be a vector of several independent variables (this includes the case where each φi${\varphi }_{i}$ is a function of a different variable, or set of variables).
The algorithm is a modification of the simplex method of linear programming applied to the dual formation of the l${l}_{\infty }$ problem (see Barrodale and Phillips (1974) and Barrodale and Phillips (1975)). The modifications are designed to improve the efficiency and stability of the simplex method for this particular application.

References

Barrodale I and Phillips C (1974) An improved algorithm for discrete Chebyshev linear approximation Proc. 4th Manitoba Conf. Numerical Mathematics 177–190 University of Manitoba, Canada
Barrodale I and Phillips C (1975) Solution of an overdetermined system of linear equations in the Chebyshev norm [F4] (Algorithm 495) ACM Trans. Math. Software 1(3) 264–270

Parameters

Compulsory Input Parameters

1:     n – int64int32nag_int scalar
The number of unknowns, n$n$ (the number of columns of the matrix A$A$).
Constraint: n1${\mathbf{n}}\ge 1$.
2:     a(lda,sda) – double array
lda, the first dimension of the array, must satisfy the constraint ldan + 3$\mathit{lda}\ge {\mathbf{n}}+3$.
a(j,i)${\mathbf{a}}\left(\mathit{j},\mathit{i}\right)$ must contain aij${a}_{\mathit{i}\mathit{j}}$, the element in the i$\mathit{i}$th row and j$\mathit{j}$th column of the matrix A$A$, for i = 1,2,,m$\mathit{i}=1,2,\dots ,m$ and j = 1,2,,n$\mathit{j}=1,2,\dots ,n$, (that is, the transpose of the matrix). The remaining elements need not be set. Preferably, the columns of the matrix A$A$ (rows of the parameter a) should be scaled before entry: see Section [Accuracy].
3:     b(m) – double array
m, the dimension of the array, must satisfy the constraint mn${\mathbf{m}}\ge {\mathbf{n}}$.
b(i)${\mathbf{b}}\left(\mathit{i}\right)$ must contain bi${b}_{\mathit{i}}$, the i$\mathit{i}$th element of the vector b$b$, for i = 1,2,,m$\mathit{i}=1,2,\dots ,m$.
4:     relerr – double scalar
Must be set to a bound on the relative error acceptable in the maximum residual at the solution.
If relerr0.0${\mathbf{relerr}}\le 0.0$, then the l${l}_{\infty }$ solution is computed, and relerr is set to 0.0$0.0$ on exit.
If relerr > 0.0${\mathbf{relerr}}>0.0$, then the function obtains instead an approximate solution for which the largest residual is less than 1.0 + relerr$1.0+{\mathbf{relerr}}$ times that of the l${l}_{\infty }$ solution; on exit, relerr contains a smaller value such that the above bound still applies. (The usual result of this option, say with relerr = 0.1${\mathbf{relerr}}=0.1$, is a saving in the number of simplex iterations).

Optional Input Parameters

1:     m – int64int32nag_int scalar
Default: The dimension of the array b.
The number of equations, m$m$ (the number of rows of the matrix A$A$).
Constraint: mn${\mathbf{m}}\ge {\mathbf{n}}$.
2:     tol – double scalar
A threshold below which numbers are regarded as zero. The recommended threshold value is 10.0 × ε$10.0×\epsilon$, where ε$\epsilon$ is the machine precision. If tol0.0${\mathbf{tol}}\le 0.0$ on entry, the recommended value is used within the function. If premature termination occurs, a larger value for tol may result in a valid solution.
Default: 0.0$0.0$.

sda lda

Output Parameters

1:     a(lda,sda) – double array
sdam + 1$\mathit{sda}\ge {\mathbf{m}}+1$.
ldan + 3$\mathit{lda}\ge {\mathbf{n}}+3$.
Contains the last simplex tableau.
2:     b(m) – double array
The i$\mathit{i}$th residual ri${\mathit{r}}_{\mathit{i}}$ corresponding to the solution vector x$x$, for i = 1,2,,m$\mathit{i}=1,2,\dots ,m$. Note however that these residuals may contain few significant figures, especially when resmax is within one or two orders of magnitude of tol. Indeed if ${\mathbf{resmax}}\le {\mathbf{tol}}$, the elements b(i)${\mathbf{b}}\left(i\right)$ may all be set to zero. It is therefore often advisable to compute the residuals directly.
3:     relerr – double scalar
Is altered as described above.
4:     x(n) – double array
If ${\mathbf{ifail}}={\mathbf{0}}$ or 1${\mathbf{1}}$, x(j)${\mathbf{x}}\left(\mathit{j}\right)$ contains the j$\mathit{j}$th element of the solution vector x$x$, for j = 1,2,,n$\mathit{j}=1,2,\dots ,n$. Whether this is an l${l}_{\infty }$ solution or an approximation to one, depends on the value of relerr on entry.
5:     resmax – double scalar
If ${\mathbf{ifail}}={\mathbf{0}}$ or 1${\mathbf{1}}$, resmax contains the absolute value of the largest residual(s) for the solution vector x$x$. (See b.)
6:     irank – int64int32nag_int scalar
If ${\mathbf{ifail}}={\mathbf{0}}$ or 1${\mathbf{1}}$, irank contains the computed rank of the matrix A$A$.
7:     iter – int64int32nag_int scalar
If ${\mathbf{ifail}}={\mathbf{0}}$ or 1${\mathbf{1}}$, iter contains the number of iterations taken by the simplex method.
8:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Note: nag_fit_glin_linf (e02gc) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:

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

W ifail = 1${\mathbf{ifail}}=1$
An optimal solution has been obtained but this may not be unique (perhaps simply because the matrix A$A$ is not of full rank, i.e., ${\mathbf{irank}}<{\mathbf{n}}$).
ifail = 2${\mathbf{ifail}}=2$
The calculations have terminated prematurely due to rounding errors. Experiment with larger values of tol or try rescaling the columns of the matrix (see Section [Further Comments]).
ifail = 3${\mathbf{ifail}}=3$
 On entry, lda < n + 3$\mathit{lda}<{\mathbf{n}}+3$, or sda < m + 1$\mathit{sda}<{\mathbf{m}}+1$, or m < n${\mathbf{m}}<{\mathbf{n}}$, or n < 1${\mathbf{n}}<1$.

Accuracy

Experience suggests that the computational accuracy of the solution x$x$ is comparable with the accuracy that could be obtained by applying Gaussian elimination with partial pivoting to the n + 1$n+1$ equations which have residuals of largest absolute value. The accuracy therefore varies with the conditioning of the problem, but has been found generally very satisfactory in practice.

The effects of m$m$ and n$n$ on the time and on the number of iterations in the simplex method vary from problem to problem, but typically the number of iterations is a small multiple of n$n$ and the total time is approximately proportional to mn2$m{n}^{2}$.
It is recommended that, before the function is entered, the columns of the matrix A$A$ are scaled so that the largest element in each column is of the order of unity. This should improve the conditioning of the matrix, and also enable the parameter tol to perform its correct function. The solution x$x$ obtained will then, of course, relate to the scaled form of the matrix. Thus if the scaling is such that, for each j = 1,2,,n$j=1,2,\dots ,n$, the elements of the j$j$th column are multiplied by the constant kj${k}_{j}$, the element xj${x}_{j}$ of the solution vector x$x$ must be multiplied by kj${k}_{j}$ if it is desired to recover the solution corresponding to the original matrix A$A$.

Example

```function nag_fit_glin_linf_example
n = int64(3);
a = zeros(6, 6);
for i = 1:5
a(1, i) = exp((i-1)/5);
a(2, i) = exp(-(i-1)/5);
a(3, i) = 1;
end
b = [4.501;
4.36;
4.333;
4.418;
4.625];
relerr = 0;
[aOut, bOut, relerrOut, x, resmax, irank, iter, ifail] = nag_fit_glin_linf(n, a, b, relerr)
```
```

aOut =

-3.0207   -5.5042    8.8604    1.0000    0.3355    6.0000
-1.4796   -4.9123    5.4459   -0.3289    0.0541   -4.0000
3.0207    5.5042   -8.3604   -0.0000    0.1645    8.0000
1.4796    4.9123   -5.9459    0.3289    0.4459   -7.0000
1.0049    2.0149    1.4822    0.0003    0.0010         0
1.0000    2.0000    3.0000    5.0000         0         0

bOut =

-0.0010
0.0007
0.0010
-0.0010
0.0010

relerrOut =

0

x =

1.0049
2.0149
1.4822

resmax =

0.0010

irank =

3

iter =

4

ifail =

0

```
```function e02gc_example
n = int64(3);
a = zeros(6, 6);
for i = 1:5
a(1, i) = exp((i-1)/5);
a(2, i) = exp(-(i-1)/5);
a(3, i) = 1;
end
b = [4.501;
4.36;
4.333;
4.418;
4.625];
relerr = 0;
[aOut, bOut, relerrOut, x, resmax, irank, iter, ifail] = e02gc(n, a, b, relerr)
```
```

aOut =

-3.0207   -5.5042    8.8604    1.0000    0.3355    6.0000
-1.4796   -4.9123    5.4459   -0.3289    0.0541   -4.0000
3.0207    5.5042   -8.3604   -0.0000    0.1645    8.0000
1.4796    4.9123   -5.9459    0.3289    0.4459   -7.0000
1.0049    2.0149    1.4822    0.0003    0.0010         0
1.0000    2.0000    3.0000    5.0000         0         0

bOut =

-0.0010
0.0007
0.0010
-0.0010
0.0010

relerrOut =

0

x =

1.0049
2.0149
1.4822

resmax =

0.0010

irank =

3

iter =

4

ifail =

0

```