NAG FL Interface
e02gaf (glin_l1sol)
1
Purpose
e02gaf calculates an solution to an over-determined system of linear equations.
2
Specification
Fortran Interface
Subroutine e02gaf ( |
m, a, lda, b, nplus2, toler, x, resid, irank, iter, iwork, ifail) |
Integer, Intent (In) |
:: |
m, lda, nplus2 |
Integer, Intent (Inout) |
:: |
ifail |
Integer, Intent (Out) |
:: |
irank, iter, iwork(m) |
Real (Kind=nag_wp), Intent (In) |
:: |
toler |
Real (Kind=nag_wp), Intent (Inout) |
:: |
a(lda,nplus2), b(m) |
Real (Kind=nag_wp), Intent (Out) |
:: |
x(nplus2), resid |
|
C Header Interface
#include <nag.h>
void |
e02gaf_ (const Integer *m, double a[], const Integer *lda, double b[], const Integer *nplus2, const double *toler, double x[], double *resid, Integer *irank, Integer *iter, Integer iwork[], Integer *ifail) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
e02gaf_ (const Integer &m, double a[], const Integer &lda, double b[], const Integer &nplus2, const double &toler, double x[], double &resid, Integer &irank, Integer &iter, Integer iwork[], Integer &ifail) |
}
|
The routine may be called by the names e02gaf or nagf_fit_glin_l1sol.
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 (the sum of the absolute values) of the residuals
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.
Typically in applications to data fitting, data consisting of
points with coordinates
are to be approximated in the
norm by a linear combination of known functions
,
This is equivalent to fitting an
solution to the over-determined system of equations
Thus if, for each value of
and
, the element
of the matrix
in the previous paragraph 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 primal formulation of the
problem (see
Barrodale and Roberts (1973) and
Barrodale and Roberts (1974)). The modification allows several neighbouring simplex vertices to be passed through in a single iteration, providing a substantial improvement in efficiency.
4
References
Barrodale I and Roberts F D K (1973) An improved algorithm for discrete linear approximation SIAM J. Numer. Anal. 10 839–848
Barrodale I and Roberts F D K (1974) Solution of an overdetermined system of equations in the -norm Comm. ACM 17(6) 319–320
5
Arguments
-
1:
– Integer
Input
-
On entry: the number of equations, (the number of rows of the matrix ).
Constraint:
.
-
2:
– Real (Kind=nag_wp) array
Input/Output
-
On entry: must contain , the element in the th row and th column of the matrix , for and . The remaining elements need not be set.
On exit: contains the last simplex tableau generated by the simplex method.
-
3:
– Integer
Input
-
On entry: the first dimension of the array
a as declared in the (sub)program from which
e02gaf is called.
Constraint:
.
-
4:
– Real (Kind=nag_wp) array
Input/Output
-
On entry: must contain , the th element of the vector , for .
On exit: the
th residual corresponding to the solution vector , for .
-
5:
– Integer
Input
-
On entry: , where is the number of unknowns (the number of columns of the matrix ).
Constraint:
.
-
6:
– Real (Kind=nag_wp)
Input
-
On entry: a non-negative value. In general
toler specifies a threshold below which numbers are regarded as zero. The recommended threshold value is
where
is the
machine precision. The recommended value can be computed within the routine by setting
toler to zero. If premature termination occurs a larger value for
toler may result in a valid solution.
Suggested value:
.
-
7:
– Real (Kind=nag_wp) array
Output
-
On exit: contains the th element of the solution vector , for . The elements and are unused.
-
8:
– Real (Kind=nag_wp)
Output
-
On exit: the sum of the absolute values of the residuals for the solution vector .
-
9:
– Integer
Output
-
On exit: the computed rank of the matrix .
-
10:
– Integer
Output
-
On exit: the number of iterations taken by the simplex method.
-
11:
– Integer array
Workspace
-
-
12:
– Integer
Input/Output
-
On entry:
ifail must be set to
,
or
to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value
or
is recommended. If message printing is undesirable, then the value
is recommended. Otherwise, the value
is recommended.
When the value or 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).
Errors or warnings detected by the routine:
-
An optimal solution has been obtained, but may not be unique.
-
Premature termination due to rounding errors. Try using larger value of
toler:
.
-
On entry, and .
Constraint: .
On entry, .
Constraint: .
On entry, and .
Constraint: .
-
More than
iterations were performed.
e02gaf has terminated without calculating a solution. The output data from the routine is as computed on the last good iteration. Consider increasing the value of
toler. Alternatively,
may be ill conditioned—try scaling its columns.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See
Section 9 in the Introduction to the NAG Library FL Interface 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 satisfied by this algorithm (i.e., those equations with zero residuals). The accuracy therefore varies with the conditioning of the problem, but has been found generally very satisfactory in practice.
8
Parallelism and Performance
e02gaf 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 taken 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
toler 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
Suppose we wish to approximate 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
e02gaf is used to solve these in the
sense.
10.1
Program Text
10.2
Program Data
10.3
Program Results