def polyval(fit, points, der=0, avg=False):
"""Evaluate polynomial generated by ``polyfit()`` on `points`.
Parameters
----------
fit, points : see polyfit()
der : int, optional
Derivative order. Only for 1D, uses np.polyder().
avg : bool, optional
Internal hack, only used by ``avgpolyval()``.
Notes
-----
For 1D we provide "analytic" derivatives using np.polyder(). For ND, we
didn't implement an equivalent machinery. For 2D, you might get away with
fitting a bispline (see Interpol2D) and use it's derivs. For ND, try rbf.py's RBF
interpolator which has at least 1st derivatives for arbitrary dimensions.
See Also
--------
:class:`PolyFit`, :class:`PolyFit1D`, :func:`polyfit`
"""
pscale, pmin = fit['pscale'], fit['pmin']
vscale, vmin = fit['vscale'], fit['vmin']
if der > 0:
assert points.shape[1] == 1, "deriv only for 1d poly (ndim=1)"
# ::-1 b/c numpy stores poly coeffs in reversed order
dcoeffs = np.polyder(fit['coeffs'][::-1], m=der)
return np.polyval(dcoeffs, (points[:,0] - pmin[0,0]) / pscale[0,0]) / \
pscale[0,0]**der * vscale
else:
vand = vander((points - pmin) / pscale, fit['deg'])
if avg:
return np.dot(vand, fit['coeffs']) * vscale
else:
return np.dot(vand, fit['coeffs']) * vscale + vmin
评论列表
文章目录