chebfit(x, y, deg, rcond=None, full=False, w=None)
Return the coefficients of a Chebyshev series of degree :None:None:`deg`
that is the least squares fit to the data values y
given at points x
. If y
is 1-D the returned coefficients will also be 1-D. If y
is 2-D multiple fits are done, one for each column of y
, and the resulting coefficients are stored in the corresponding columns of a 2-D return. The fitted polynomial(s) are in the form
where n
is :None:None:`deg`
.
The solution is the coefficients of the Chebyshev series :None:None:`p`
that minimizes the sum of the weighted squared errors
where $w_j$ are the weights. This problem is solved by setting up as the (typically) overdetermined matrix equation
$$V(x) * c = w * y,$$where :None:None:`V`
is the weighted pseudo Vandermonde matrix of x
, c
are the coefficients to be solved for, w
are the weights, and y
are the observed values. This equation is then solved using the singular value decomposition of :None:None:`V`
.
If some of the singular values of :None:None:`V`
are so small that they are neglected, then a RankWarning
will be issued. This means that the coefficient values may be poorly determined. Using a lower order fit will usually get rid of the warning. The :None:None:`rcond`
parameter can also be set to a value smaller than its default, but the resulting fit may be spurious and have large contributions from roundoff error.
Fits using Chebyshev series are usually better conditioned than fits using power series, but much can depend on the distribution of the sample points and the smoothness of the data. If the quality of the fit is inadequate splines may be a good alternative.
x-coordinates of the M sample points (x[i], y[i])
.
y-coordinates of the sample points. Several data sets of sample points sharing the same x-coordinates can be fitted at once by passing in a 2D-array that contains one dataset per column.
Degree(s) of the fitting polynomials. If :None:None:`deg`
is a single integer, all terms up to and including the :None:None:`deg`
'th term are included in the fit. For NumPy versions >= 1.11.0 a list of integers specifying the degrees of the terms to include may be used instead.
Relative condition number of the fit. Singular values smaller than this relative to the largest singular value will be ignored. The default value is len(x)*eps, where eps is the relative precision of the float type, about 2e-16 in most cases.
Switch determining nature of return value. When it is False (the default) just the coefficients are returned, when True diagnostic information from the singular value decomposition is also returned.
Weights. If not None, the weight w[i]
applies to the unsquared residual y[i] - y_hat[i]
at x[i]
. Ideally the weights are chosen so that the errors of the products w[i]*y[i]
all have the same variance. When using inverse-variance weighting, use w[i] = 1/sigma(y[i])
. The default value is None.
Chebyshev coefficients ordered from low to high. If y
was 2-D, the coefficients for the data in column k of y
are in column k
.
These values are only returned if full == True
residuals -- sum of squared residuals of the least squares fit
rank -- the numerical rank of the scaled Vandermonde matrix
singular_values -- singular values of the scaled Vandermonde matrix
rcond -- value of :None:None:`rcond`
.
For more details, see numpy.linalg.lstsq
.
Least squares fit of Chebyshev series to data.
The rank of the coefficient matrix in the least-squares fit is deficient. The warning is only raised if full == False
. The warnings can be turned off by
>>> import warnings >>> warnings.simplefilter('ignore', np.RankWarning)
chebval
Evaluates a Chebyshev series.
chebvander
Vandermonde matrix of Chebyshev series.
chebweight
Chebyshev weight function.
numpy.linalg.lstsq
Computes a least-squares fit from the matrix.
scipy.interpolate.UnivariateSpline
Computes spline fits.
The following pages refer to to this document either explicitly or contain code examples using this.
numpy.polynomial.polynomial.polyfit
numpy.polynomial.hermite_e.hermefit
numpy.polynomial.hermite.hermfit
numpy.polynomial.legendre.legfit
numpy.polynomial.laguerre.lagfit
numpy.polynomial
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them