Least squares fit of Chebyshev series to data. Return the coefficients of a Chebyshev series of degree `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,
(x, y, deg, rcond=None, full=False, w=None)
| 1545 | |
| 1546 | |
| 1547 | def chebfit(x, y, deg, rcond=None, full=False, w=None): |
| 1548 | """ |
| 1549 | Least squares fit of Chebyshev series to data. |
| 1550 | |
| 1551 | Return the coefficients of a Chebyshev series of degree `deg` that is the |
| 1552 | least squares fit to the data values `y` given at points `x`. If `y` is |
| 1553 | 1-D the returned coefficients will also be 1-D. If `y` is 2-D multiple |
| 1554 | fits are done, one for each column of `y`, and the resulting |
| 1555 | coefficients are stored in the corresponding columns of a 2-D return. |
| 1556 | The fitted polynomial(s) are in the form |
| 1557 | |
| 1558 | .. math:: p(x) = c_0 + c_1 * T_1(x) + ... + c_n * T_n(x), |
| 1559 | |
| 1560 | where `n` is `deg`. |
| 1561 | |
| 1562 | Parameters |
| 1563 | ---------- |
| 1564 | x : array_like, shape (M,) |
| 1565 | x-coordinates of the M sample points ``(x[i], y[i])``. |
| 1566 | y : array_like, shape (M,) or (M, K) |
| 1567 | y-coordinates of the sample points. Several data sets of sample |
| 1568 | points sharing the same x-coordinates can be fitted at once by |
| 1569 | passing in a 2D-array that contains one dataset per column. |
| 1570 | deg : int or 1-D array_like |
| 1571 | Degree(s) of the fitting polynomials. If `deg` is a single integer, |
| 1572 | all terms up to and including the `deg`'th term are included in the |
| 1573 | fit. For NumPy versions >= 1.11.0 a list of integers specifying the |
| 1574 | degrees of the terms to include may be used instead. |
| 1575 | rcond : float, optional |
| 1576 | Relative condition number of the fit. Singular values smaller than |
| 1577 | this relative to the largest singular value will be ignored. The |
| 1578 | default value is len(x)*eps, where eps is the relative precision of |
| 1579 | the float type, about 2e-16 in most cases. |
| 1580 | full : bool, optional |
| 1581 | Switch determining nature of return value. When it is False (the |
| 1582 | default) just the coefficients are returned, when True diagnostic |
| 1583 | information from the singular value decomposition is also returned. |
| 1584 | w : array_like, shape (`M`,), optional |
| 1585 | Weights. If not None, the weight ``w[i]`` applies to the unsquared |
| 1586 | residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are |
| 1587 | chosen so that the errors of the products ``w[i]*y[i]`` all have the |
| 1588 | same variance. When using inverse-variance weighting, use |
| 1589 | ``w[i] = 1/sigma(y[i])``. The default value is None. |
| 1590 | |
| 1591 | .. versionadded:: 1.5.0 |
| 1592 | |
| 1593 | Returns |
| 1594 | ------- |
| 1595 | coef : ndarray, shape (M,) or (M, K) |
| 1596 | Chebyshev coefficients ordered from low to high. If `y` was 2-D, |
| 1597 | the coefficients for the data in column k of `y` are in column |
| 1598 | `k`. |
| 1599 | |
| 1600 | [residuals, rank, singular_values, rcond] : list |
| 1601 | These values are only returned if ``full == True`` |
| 1602 | |
| 1603 | - residuals -- sum of squared residuals of the least squares fit |
| 1604 | - rank -- the numerical rank of the scaled Vandermonde matrix |