NAG Library Routine Document
e02gcf
(glin_linf)
1
Purpose
e02gcf calculates an solution to an over-determined system of linear equations.
2
Specification
Fortran Interface
Subroutine e02gcf ( |
m,
n,
sda,
lda,
a,
b,
tol,
relerr,
x,
resmax,
irank,
iter,
ifail) |
Integer, Intent (In) | :: |
m,
n,
sda,
lda | Integer, Intent (Inout) | :: |
ifail | Integer, Intent (Out) | :: |
irank,
iter | Real (Kind=nag_wp), Intent (In) | :: |
tol | Real (Kind=nag_wp), Intent (Inout) | :: |
a(lda,sda),
b(m),
relerr | Real (Kind=nag_wp), Intent (Out) | :: |
x(n),
resmax |
|
C Header Interface
#include nagmk26.h
void |
e02gcf_ (
const Integer *m,
const Integer *n,
const Integer *sda,
const Integer *lda,
double a[],
double b[],
const double *tol,
double *relerr,
double x[],
double *resmax,
Integer *irank,
Integer *iter,
Integer *ifail) |
|
3
Description
Given a matrix
with
rows and
columns
and a vector
with
elements, the routine calculates an
solution to the over-determined system of equations
That is to say, it calculates a vector
, with
elements, which minimizes the
norm of the residuals (the absolutely largest residual)
where the residuals
are given by
Here is the element in row and column of , is the th element of and the th element of . The matrix need not be of full rank. The solution is not unique in this case, and may not be unique even if is of full rank.
Alternatively, in applications where a complete minimization of the
norm is not necessary, you may obtain an approximate solution, usually in shorter time, by giving an appropriate value to the argument
relerr.
Typically in applications to data fitting, data consisting of
points with coordinates
is to be approximated in the
norm by a linear combination of known functions
,
This is equivalent to finding an
solution to the over-determined system of equations
Thus if, for each value of and the element of the matrix above is set equal to the value of and is set equal to , the solution vector will contain the required values of the . Note that the independent variable above can, instead, be a vector of several independent variables (this includes the case where each 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
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
Arguments
- 1: – IntegerInput
-
On entry: the number of equations, (the number of rows of the matrix ).
Constraint:
.
- 2: – IntegerInput
-
On entry: the number of unknowns, (the number of columns of the matrix ).
Constraint:
.
- 3: – IntegerInput
-
On entry: the second dimension of the array
a as declared in the (sub)program from which
e02gcf is called.
Constraint:
.
- 4: – IntegerInput
-
On entry: the first dimension of the array
a as declared in the (sub)program from which
e02gcf is called.
Constraint:
.
- 5: – Real (Kind=nag_wp) arrayInput/Output
-
On entry:
must contain
, the element in the
th row and
th column of the matrix
, for
and
, (that is, the
transpose of the matrix). The remaining elements need not be set. Preferably, the columns of the matrix
(rows of the argument
a) should be scaled before entry: see
Section 7.
On exit: contains the last simplex tableau.
- 6: – Real (Kind=nag_wp) arrayInput/Output
-
On entry: must contain , the th element of the vector , for .
On exit: the
th residual
corresponding to the solution vector
, for
. 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
, the elements
may all be set to zero. It is therefore often advisable to compute the residuals directly.
- 7: – Real (Kind=nag_wp)Input
-
On entry: a threshold below which numbers are regarded as zero. The recommended threshold value is
, where
is the
machine precision. If
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:
.
- 8: – 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
, the
solution is computed, and
relerr is set to
on exit.
If
, the routine obtains instead an approximate solution for which the largest residual is less than
times that of the
solution; on exit,
relerr contains a smaller value such that the above bound still applies. (The usual result of this option, say with
, is a saving in the number of simplex iterations).
On exit: is altered as described above.
- 9: – Real (Kind=nag_wp) arrayOutput
-
On exit: if
or
,
contains the
th element of the solution vector
, for
. Whether this is an
solution or an approximation to one, depends on the value of
relerr on entry.
- 10: – Real (Kind=nag_wp)Output
-
On exit: if
or
,
resmax contains the absolute value of the largest residual(s) for the solution vector
. (See
b.)
- 11: – IntegerOutput
-
On exit: if
or
,
irank contains the computed rank of the matrix
.
- 12: – IntegerOutput
-
On exit: if
or
,
iter contains the number of iterations taken by the simplex method.
- 13: – IntegerInput/Output
-
On entry:
ifail must be set to
,
. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, because for this routine the values of the output arguments may be useful even if
on exit, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, 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:
-
An optimal solution has been obtained but this may not be unique (perhaps simply because the matrix is not of full rank, i.e., ).
-
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).
-
On entry, | , |
or | , |
or | , |
or | . |
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
Accuracy
Experience suggests that the computational accuracy of the solution is comparable with the accuracy that could be obtained by applying Gaussian elimination with partial pivoting to the 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
e02gcf is not threaded in any implementation.
The effects of and 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 and the total time is approximately proportional to .
It is recommended that, before the routine is entered, the columns of the matrix
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 argument
tol to perform its correct function. The solution
obtained will then, of course, relate to the scaled form of the matrix. Thus if the scaling is such that, for each
, the elements of the
th column are multiplied by the constant
, the element
of the solution vector
must be multiplied by
if it is desired to recover the solution corresponding to the original matrix
.
10
Example
This example approximates a set of data by a curve of the form
where
,
and
are unknown. Given values
at
points
we may form the over-determined set of equations for
,
and
e02gcf is used to solve these in the 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)