NAG Library Function Document
nag_linf_fit (e02gcc) calculates an solution to an over-determined system of linear equations.
||nag_linf_fit (Nag_OrderType order,
Given a matrix
and a vector
elements, the function calculates an
solution to the over-determined system of equations
That is to say, it calculates a vector
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.
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
order – Nag_OrderTypeInput
: the order
argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by
. See Section 184.108.40.206
in the Essential Introduction for a more detailed explanation of the use of this argument.
m – IntegerInput
On entry: the number of equations, (the number of rows of the matrix ).
n – IntegerInput
On entry: the number of unknowns, (the number of columns of the matrix ).
a – doubleInput/Output
the dimension, dim
, of the array
must be at least
appears in this document, it refers to the array element
- when ;
- when .
, the element in the
th row and
th column of the matrix
, (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.
b[m] – doubleInput/Output
On entry: must contain , the th element of the vector , for .
corresponding to the solution vector
. 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.
tol – doubleInput
: a threshold below which numbers are regarded as zero. The recommended threshold value is
is the machine precision
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.
relerr – double *Input/Output
: must be set to a bound on the relative error acceptable in the maximum residual at the solution.
, then the
solution is computed, and relerr
is set to
, then the function 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.
x[n] – doubleOutput
: if an optimal but not necessarily unique solution is found,
th element of the solution vector
. Whether this is an
solution or an approximation to one, depends on the value of relerr
resmax – double *Output
: if an optimal but not necessarily unique solution is found, resmax
contains the absolute value of the largest residual(s) for the solution vector
. (See b
rank – Integer *Output
: if an optimal but not necessarily unique solution is found, rank
contains the computed rank of the matrix
iter – Integer *Output
: if an optimal but not necessarily unique solution is found, iter
contains the number of iterations taken by the simplex method.
fail – NagError *Input/Output
The NAG error argument (see Section 3.6
in the Essential Introduction).
6 Error Indicators and Warnings
Dynamic memory allocation failed.
On entry, argument had an illegal value.
On entry, .
On entry, and .
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG
An optimal solution has been obtained, but may not be unique.
Premature termination due to rounding errors. Try using larger value of tol
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
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 function 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
This example approximates a set of data by a curve of the form
are unknown. Given values
we may form the over-determined set of equations for
nag_linf_fit (e02gcc) is used to solve these in the sense.
10.1 Program Text
Program Text (e02gcce.c)
10.2 Program Data
Program Data (e02gcce.d)
10.3 Program Results
Program Results (e02gcce.r)