Function adas.xxmnmx

def xxmnmx(xin, yin, maxdeg=8, tol=5.0, log=False)

Minimax polynominal fit to tabulated data..

Parameters

xin : float, array
independent variable
yin : float, array
dependent variable
maxdeg : int, optional
maximum possible degree of polynomial allowed in the minimax fitting, defaults to 8 but maximum is 25
tol : float, optional
fit tolerance as a percentage
log : bool, optional
if True fit in log-log space, default is False

Returns

coeff : float, array
polynominal coefficients of fit
info : string
an 80 character string summarizing the success of the fit

Notes

Note tha the coefficients are in the opposite order to those from numpy.polyfit. ie the fit is evaluated: c[0] + c[1]x + c[2]x**2 + ....

There are other differences which distinguish this from numpy.polyfit. The routine determines the number of coefficients up to a maximum of maxdeg+1 and the fit tolerance is specified as a percentage. This is a guide and the routine returns a string giving the accuracy achieved even if it is worse than the tolerance requested. It is the same algorithm used in ADAS interactive codes which offer a polynominal fit.

Calls a fortran based shared object file - not pure python.

Version History

  • Martin O'Mullane, 15-07-2020
    • First version

Example

>>> import adas as adas
>>> import numpy as np
>>> x=np.array([0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0])
>>> y=np.array([0.25, 0.16, 0.09, 0.04, 0.01, 0.00, 0.01, 0.04, 0.09, 0.16, 0.25])
>>> adas.xxmnmx(x,y,maxdeg=2)
(array([ 0.25, -1.  ,  1.  ]),
'LINFIT - DEGREE= 2  ACCURACY=  0.00%  END GRADIENT: LOWER=  -1.00 UPPER=   1.00 ')
>>> np.polyfit(x,y,2)
array([ 1.  , -1.  ,  0.25])