naginterfaces.library.fit.glin_linf¶
- naginterfaces.library.fit.glin_linf(n, a, b, relerr, tol=0.0)[source]¶
glin_linf
calculates an solution to an overdetermined system of linear equations.For full information please refer to the NAG Library document for e02gc
https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/e02/e02gcf.html
- Parameters
- nint
The number of unknowns, (the number of columns of the matrix ).
- afloat, array-like, shape
must contain , the element in the th row and th column of the matrix , for , for , (that is, the transpose of the matrix). The remaining elements need not be set. Preferably, the columns of the matrix (rows of the argument ) should be scaled before entry: see Accuracy.
- bfloat, array-like, shape
must contain , the th element of the vector , for .
- relerrfloat
Must be set to a bound on the relative error acceptable in the maximum residual at the solution.
If , the solution is computed, and is set to on exit.
If , the function obtains instead an approximate solution for which the largest residual is less than times that of the solution; on exit, 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).
- tolfloat, optional
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 function. If premature termination occurs, a larger value for may result in a valid solution.
- Returns
- afloat, ndarray, shape
Contains the last simplex tableau.
- bfloat, ndarray, shape
The th residual corresponding to the solution vector , for . Note however that these residuals may contain few significant figures, especially when is within one or two orders of magnitude of . Indeed if , the elements may all be set to zero. It is, therefore, often advisable to compute the residuals directly.
- relerrfloat
Is altered as described above.
- xfloat, ndarray, shape
If the function exits successfully or = 1, contains the th element of the solution vector , for . Whether this is an solution or an approximation to one, depends on the value of on entry.
- resmaxfloat
If the function exits successfully or = 1, contains the absolute value of the largest residual(s) for the solution vector . (See .)
- irankint
If the function exits successfully or = 1, contains the computed rank of the matrix .
- iteraint
If the function exits successfully or = 1, contains the number of iterations taken by the simplex method.
- Raises
- NagValueError
- (errno )
Premature termination due to rounding errors. Try using larger value of : .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, and .
Constraint: .
- Warns
- NagAlgorithmicWarning
- (errno )
An optimal solution has been obtained, but may not be unique.
- Notes
Given a matrix with rows and columns and a vector with elements, the function calculates an solution to the overdetermined 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 .
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 overdetermined 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.
- 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