summaryrefslogtreecommitdiff
path: root/numpy/polynomial/legendre.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2011-12-27 17:54:09 -0700
committerCharles Harris <charlesr.harris@gmail.com>2012-01-09 11:09:36 -0700
commitc462637f9b398600d25ca449aef8586d8d9d6210 (patch)
tree82ac8cec0eb48a220f311f53ef4c2265c782b198 /numpy/polynomial/legendre.py
parent08c8c54051e27f80f7e30646ef367eb709b3e6cf (diff)
downloadnumpy-c462637f9b398600d25ca449aef8586d8d9d6210.tar.gz
DOC: Document xxxfit functions in the polynomial package modules.
Diffstat (limited to 'numpy/polynomial/legendre.py')
-rw-r--r--numpy/polynomial/legendre.py39
1 files changed, 24 insertions, 15 deletions
diff --git a/numpy/polynomial/legendre.py b/numpy/polynomial/legendre.py
index 319fb505b..da2c2d846 100644
--- a/numpy/polynomial/legendre.py
+++ b/numpy/polynomial/legendre.py
@@ -1326,9 +1326,16 @@ def legfit(x, y, deg, rcond=None, full=False, w=None):
"""
Least squares fit of Legendre series to data.
- Fit a Legendre series ``p(x) = p[0] * P_{0}(x) + ... + p[deg] *
- P_{deg}(x)`` of degree `deg` to points `(x, y)`. Returns a vector of
- coefficients `p` that minimises the squared error.
+ Return the coefficients of a Legendre 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, 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
+
+ .. math:: p(x) = c_0 + c_1 * L_1(x) + ... + c_n * L_n(x),
+
+ where `n` is `deg`.
Parameters
----------
@@ -1355,6 +1362,8 @@ def legfit(x, y, deg, rcond=None, full=False, w=None):
weights are chosen so that the errors of the products ``w[i]*y[i]``
all have the same variance. The default value is None.
+ .. versionadded:: 1.5.0
+
Returns
-------
coef : ndarray, shape (M,) or (M, K)
@@ -1379,31 +1388,31 @@ def legfit(x, y, deg, rcond=None, full=False, w=None):
See Also
--------
+ chebfit, polyfit, lagfit, hermfit, hermefit
legval : Evaluates a Legendre series.
legvander : Vandermonde matrix of Legendre series.
- polyfit : least squares fit using polynomials.
- chebfit : least squares fit using Chebyshev series.
+ legweight : Legendre weight function (= 1).
linalg.lstsq : Computes a least-squares fit from the matrix.
scipy.interpolate.UnivariateSpline : Computes spline fits.
Notes
-----
- The solution are the coefficients ``c[i]`` of the Legendre series
- ``P(x)`` that minimizes the squared error
+ The solution is the coefficients of the Legendre series `p` that
+ minimizes the sum of the weighted squared errors
- ``E = \\sum_j |y_j - P(x_j)|^2``.
+ .. math:: E = \\sum_j w_j^2 * |y_j - p(x_j)|^2,
- This problem is solved by setting up as the overdetermined matrix
- equation
+ where :math:`w_j` are the weights. This problem is solved by setting up
+ as the (typically) overdetermined matrix equation
- ``V(x)*c = y``,
+ .. math:: V(x) * c = w * y,
- where ``V`` is the Vandermonde matrix of `x`, the elements of ``c`` are
- the coefficients to be solved for, and the elements of `y` are the
+ where `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 ``V``.
+ decomposition of `V`.
- If some of the singular values of ``V`` are so small that they are
+ If some of the singular values of `V` are so small that they are
neglected, then a `RankWarning` will be issued. This means that the
coeficient values may be poorly determined. Using a lower order fit
will usually get rid of the warning. The `rcond` parameter can also be