E02GCF (PDF version)
E02 Chapter Contents
E02 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

E02GCF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

E02GCF calculates an l solution to an over-determined system of linear equations.

2  Specification

SUBROUTINE E02GCF ( M, N, SDA, LDA, A, B, TOL, RELERR, X, RESMAX, IRANK, ITER, IFAIL)
INTEGER  M, N, SDA, LDA, IRANK, ITER, IFAIL
REAL (KIND=nag_wp)  A(LDA,SDA), B(M), TOL, RELERR, X(N), RESMAX

3  Description

Given a matrix A with m rows and n columns mn and a vector b with m elements, the routine calculates an l solution to the over-determined system of equations
Ax=b.  
That is to say, it calculates a vector x, with n elements, which minimizes the l norm of the residuals (the absolutely largest residual)
rx = max 1im ri  
where the residuals ri are given by
ri = bi - j=1n aij xj ,   i=1,2,,m .  
Here aij is the element in row i and column j of A, bi is the ith element of b and xj the jth element of x. The matrix A need not be of full rank. The solution is not unique in this case, and may not be unique even if A is of full rank.
Alternatively, in applications where a complete minimization of the l 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 points with coordinates ti,yi is to be approximated in the l norm by a linear combination of known functions ϕjt,
α1ϕ1t+α2ϕ2t++αnϕnt.  
This is equivalent to finding an l solution to the over-determined system of equations
j=1n ϕj ti αj = yi ,   i=1,2,,m .  
Thus if, for each value of i and j the element aij of the matrix A above is set equal to the value of ϕjti and bi is set equal to yi, the solution vector x will contain the required values of the αj. Note that the independent variable t above can, instead, be a vector of several independent variables (this includes the case where each ϕ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 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.

4  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

5  Parameters

1:     M – INTEGERInput
On entry: the number of equations, m (the number of rows of the matrix A).
Constraint: MN.
2:     N – INTEGERInput
On entry: the number of unknowns, n (the number of columns of the matrix A).
Constraint: N1.
3:     SDA – INTEGERInput
On entry: the second dimension of the array A as declared in the (sub)program from which E02GCF is called.
Constraint: SDAM+1.
4:     LDA – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which E02GCF is called.
Constraint: LDAN+3.
5:     ALDASDA – REAL (KIND=nag_wp) arrayInput/Output
On entry: Aji must contain aij, the element in the ith row and jth column of the matrix A, for i=1,2,,m and j=1,2,,n, (that is, the transpose of the matrix). The remaining elements need not be set. Preferably, the columns of the matrix A (rows of the parameter A) should be scaled before entry: see Section 7.
On exit: contains the last simplex tableau.
6:     BM – REAL (KIND=nag_wp) arrayInput/Output
On entry: Bi must contain bi, the ith element of the vector b, for i=1,2,,m.
On exit: the ith residual ri corresponding to the solution vector x, for i=1,2,,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 RESMAXTOL, the elements Bi may all be set to zero. It is therefore often advisable to compute the residuals directly.
7:     TOL – REAL (KIND=nag_wp)Input
On entry: a threshold below which numbers are regarded as zero. The recommended threshold value is 10.0×ε, where ε is the machine precision. If TOL0.0 on entry, the recommended value is used within the routine. If premature termination occurs, a larger value for TOL may result in a valid solution.
Suggested value: 0.0.
8:     RELERR – REAL (KIND=nag_wp)Input/Output
On entry: must be set to a bound on the relative error acceptable in the maximum residual at the solution.
If RELERR0.0, then the l solution is computed, and RELERR is set to 0.0 on exit.
If RELERR>0.0, then the routine obtains instead an approximate solution for which the largest residual is less than 1.0+RELERR times that of the l 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, is a saving in the number of simplex iterations).
On exit: is altered as described above.
9:     XN – REAL (KIND=nag_wp) arrayOutput
On exit: if IFAIL=0 or 1, Xj contains the jth element of the solution vector x, for j=1,2,,n. Whether this is an l solution or an approximation to one, depends on the value of RELERR on entry.
10:   RESMAX – REAL (KIND=nag_wp)Output
On exit: if IFAIL=0 or 1, RESMAX contains the absolute value of the largest residual(s) for the solution vector x. (See B.)
11:   IRANK – INTEGEROutput
On exit: if IFAIL=0 or 1, IRANK contains the computed rank of the matrix A.
12:   ITER – INTEGEROutput
On exit: if IFAIL=0 or 1, ITER contains the number of iterations taken by the simplex method.
13:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if IFAIL0 on exit, the recommended value is -1. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Note: E02GCF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
IFAIL=1
An optimal solution has been obtained but this may not be unique (perhaps simply because the matrix A is not of full rank, i.e., IRANK<N).
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 9).
IFAIL=3
On entry,LDA<N+3,
orSDA<M+1,
orM<N,
orN<1.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

7  Accuracy

Experience suggests that the computational accuracy of the solution x is comparable with the accuracy that could be obtained by applying Gaussian elimination with partial pivoting to the 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.

8  Parallelism and Performance

Not applicable.

9  Further Comments

The effects of m and 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 and the total time is approximately proportional to mn2.
It is recommended that, before the routine is entered, the columns of the matrix 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 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, the elements of the jth column are multiplied by the constant kj, the element xj of the solution vector x must be multiplied by kj if it is desired to recover the solution corresponding to the original matrix A.

10  Example

This example approximates a set of data by a curve of the form
y=Ket+Le-t+M  
where K, L and M are unknown. Given values yi at 5 points ti we may form the over-determined set of equations for K, L and M 
etiK+e-tiL+M=yi,  i=1,2,,5.  
E02GCF is used to solve these in the l sense.

10.1  Program Text

Program Text (e02gcfe.f90)

10.2  Program Data

Program Data (e02gcfe.d)

10.3  Program Results

Program Results (e02gcfe.r)


E02GCF (PDF version)
E02 Chapter Contents
E02 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2015