Documentation
¶
Overview ¶
Package polynomial is a Go port of numpy.polynomial: the six polynomial classes sharing the ABCPolyBase API (numpy _polybase.py), each with its own basis arithmetic ported from the corresponding numpy module.
Translated in part from NumPy (numpy/polynomial), BSD-3-Clause; see LICENSES/numpy-BSD3-CLAUSE.txt.
class numpy module basis Polynomial polynomial.py power basis x^k Chebyshev chebyshev.py T_k, first kind Legendre legendre.py P_k Hermite hermite.py He_k(x/2)·..., physicists' H_k HermiteE hermite_e.py probabilists' He_k Laguerre laguerre.py L_k
Coefficients are ordered lowest degree first, like numpy. Each class maps its domain onto its window with a linear map (polyutils.mapdomain) before evaluating; Call applies the map, Val evaluates raw window coordinates.
Skipped relative to the numpy 72-method class surface (documented API cut): val2d/val3d/valnd/grid2d/grid3d, the public mapparms/getdomain functions, cross-kind Convert (only same-kind domain/window conversion), fromroots with explicit domain/window arguments, integ with explicit lbnd, Fit with explicit domain/window/rcond/full/w, basis/basisLine/interpolate/linspace/ cutdeg/degree/has_samecoef and the legacy np.poly1d function family.
Index ¶
- type Base
- func (b Base[T]) BasisName() string
- func (b Base[T]) Call(x *numgo.Array[T]) *numgo.Array[T]
- func (b Base[T]) Coef() []T
- func (b Base[T]) Companion() *numgo.Array[T]
- func (b Base[T]) Domain() [2]T
- func (b Base[T]) Len() int
- func (b Base[T]) Roots() *numgo.Array[complex128]
- func (b Base[T]) String() string
- func (b Base[T]) Val(x *numgo.Array[T]) *numgo.Array[T]
- func (b Base[T]) Vander(x *numgo.Array[T], deg int) *numgo.Array[T]
- func (b Base[T]) Window() [2]T
- type Chebyshev
- func (c *Chebyshev[T]) Add(o *Chebyshev[T]) *Chebyshev[T]
- func (c *Chebyshev[T]) Convert(domain, window [2]T) *Chebyshev[T]
- func (c *Chebyshev[T]) Copy() *Chebyshev[T]
- func (c *Chebyshev[T]) Deriv(m int) *Chebyshev[T]
- func (c *Chebyshev[T]) Div(o *Chebyshev[T]) (*Chebyshev[T], *Chebyshev[T])
- func (c *Chebyshev[T]) Fit(x, y *numgo.Array[T], deg int) *Chebyshev[T]
- func (c *Chebyshev[T]) Integ(m int, k ...T) *Chebyshev[T]
- func (c *Chebyshev[T]) Mul(o *Chebyshev[T]) *Chebyshev[T]
- func (c *Chebyshev[T]) Pow(n int) *Chebyshev[T]
- func (c *Chebyshev[T]) Sub(o *Chebyshev[T]) *Chebyshev[T]
- func (c *Chebyshev[T]) Trim(tol T) *Chebyshev[T]
- func (c *Chebyshev[T]) Truncate(size int) *Chebyshev[T]
- type Hermite
- func (h *Hermite[T]) Add(o *Hermite[T]) *Hermite[T]
- func (h *Hermite[T]) Convert(domain, window [2]T) *Hermite[T]
- func (h *Hermite[T]) Copy() *Hermite[T]
- func (h *Hermite[T]) Deriv(m int) *Hermite[T]
- func (h *Hermite[T]) Div(o *Hermite[T]) (*Hermite[T], *Hermite[T])
- func (h *Hermite[T]) Fit(x, y *numgo.Array[T], deg int) *Hermite[T]
- func (h *Hermite[T]) Integ(m int, k ...T) *Hermite[T]
- func (h *Hermite[T]) Mul(o *Hermite[T]) *Hermite[T]
- func (h *Hermite[T]) Pow(n int) *Hermite[T]
- func (h *Hermite[T]) Sub(o *Hermite[T]) *Hermite[T]
- func (h *Hermite[T]) Trim(tol T) *Hermite[T]
- func (h *Hermite[T]) Truncate(size int) *Hermite[T]
- type HermiteE
- func (h *HermiteE[T]) Add(o *HermiteE[T]) *HermiteE[T]
- func (h *HermiteE[T]) Convert(domain, window [2]T) *HermiteE[T]
- func (h *HermiteE[T]) Copy() *HermiteE[T]
- func (h *HermiteE[T]) Deriv(m int) *HermiteE[T]
- func (h *HermiteE[T]) Div(o *HermiteE[T]) (*HermiteE[T], *HermiteE[T])
- func (h *HermiteE[T]) Fit(x, y *numgo.Array[T], deg int) *HermiteE[T]
- func (h *HermiteE[T]) Integ(m int, k ...T) *HermiteE[T]
- func (h *HermiteE[T]) Mul(o *HermiteE[T]) *HermiteE[T]
- func (h *HermiteE[T]) Pow(n int) *HermiteE[T]
- func (h *HermiteE[T]) Sub(o *HermiteE[T]) *HermiteE[T]
- func (h *HermiteE[T]) Trim(tol T) *HermiteE[T]
- func (h *HermiteE[T]) Truncate(size int) *HermiteE[T]
- type Laguerre
- func (l *Laguerre[T]) Add(o *Laguerre[T]) *Laguerre[T]
- func (l *Laguerre[T]) Convert(domain, window [2]T) *Laguerre[T]
- func (l *Laguerre[T]) Copy() *Laguerre[T]
- func (l *Laguerre[T]) Deriv(m int) *Laguerre[T]
- func (l *Laguerre[T]) Div(o *Laguerre[T]) (*Laguerre[T], *Laguerre[T])
- func (l *Laguerre[T]) Fit(x, y *numgo.Array[T], deg int) *Laguerre[T]
- func (l *Laguerre[T]) Integ(m int, k ...T) *Laguerre[T]
- func (l *Laguerre[T]) Mul(o *Laguerre[T]) *Laguerre[T]
- func (l *Laguerre[T]) Pow(n int) *Laguerre[T]
- func (l *Laguerre[T]) Sub(o *Laguerre[T]) *Laguerre[T]
- func (l *Laguerre[T]) Trim(tol T) *Laguerre[T]
- func (l *Laguerre[T]) Truncate(size int) *Laguerre[T]
- type Legendre
- func (l *Legendre[T]) Add(o *Legendre[T]) *Legendre[T]
- func (l *Legendre[T]) Convert(domain, window [2]T) *Legendre[T]
- func (l *Legendre[T]) Copy() *Legendre[T]
- func (l *Legendre[T]) Deriv(m int) *Legendre[T]
- func (l *Legendre[T]) Div(o *Legendre[T]) (*Legendre[T], *Legendre[T])
- func (l *Legendre[T]) Fit(x, y *numgo.Array[T], deg int) *Legendre[T]
- func (l *Legendre[T]) Integ(m int, k ...T) *Legendre[T]
- func (l *Legendre[T]) Mul(o *Legendre[T]) *Legendre[T]
- func (l *Legendre[T]) Pow(n int) *Legendre[T]
- func (l *Legendre[T]) Sub(o *Legendre[T]) *Legendre[T]
- func (l *Legendre[T]) Trim(tol T) *Legendre[T]
- func (l *Legendre[T]) Truncate(size int) *Legendre[T]
- type Polynomial
- func (p *Polynomial[T]) Add(o *Polynomial[T]) *Polynomial[T]
- func (p *Polynomial[T]) Convert(domain, window [2]T) *Polynomial[T]
- func (p *Polynomial[T]) Copy() *Polynomial[T]
- func (p *Polynomial[T]) Deriv(m int) *Polynomial[T]
- func (p *Polynomial[T]) Div(o *Polynomial[T]) (*Polynomial[T], *Polynomial[T])
- func (p *Polynomial[T]) Fit(x, y *numgo.Array[T], deg int) *Polynomial[T]
- func (p *Polynomial[T]) Integ(m int, k ...T) *Polynomial[T]
- func (p *Polynomial[T]) Mul(o *Polynomial[T]) *Polynomial[T]
- func (p *Polynomial[T]) Pow(n int) *Polynomial[T]
- func (p *Polynomial[T]) Sub(o *Polynomial[T]) *Polynomial[T]
- func (p *Polynomial[T]) Trim(tol T) *Polynomial[T]
- func (p *Polynomial[T]) Truncate(size int) *Polynomial[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Base ¶
Base holds the state shared by the six polynomial classes: coefficients (lowest degree first), domain/window and the class-specific math hooks. It is embedded by Polynomial, Chebyshev, Legendre, Hermite, HermiteE and Laguerre.
func (Base[T]) Call ¶
Call maps x from the domain onto the window, then evaluates (numpy __call__). The input shape is preserved.
func (Base[T]) Coef ¶
func (b Base[T]) Coef() []T
Coef returns a copy of the coefficients (lowest degree first).
func (Base[T]) Domain ¶
func (b Base[T]) Domain() [2]T
Domain returns the domain interval the argument is mapped from.
func (Base[T]) Roots ¶
func (b Base[T]) Roots() *numgo.Array[complex128]
Roots returns the series roots mapped from window to domain coordinates, sorted by real then imaginary part. Values are complex128 because roots of real series may be complex conjugate pairs.
func (Base[T]) Val ¶
Val evaluates the series at each element of x, which must already be in window coordinates. The input shape is preserved.
type Chebyshev ¶
Chebyshev is the Chebyshev series of the first kind c[0]*T0 + c[1]*T1 + ... (numpy polynomial.chebyshev, class Chebyshev). Default domain and window [-1,1].
func NewChebyshev ¶
NewChebyshev builds a Chebyshev series from coefficients, lowest degree first. The coefficients are copied.
func NewChebyshevDomain ¶
NewChebyshevDomain is NewChebyshev with an explicit domain and window.
func NewChebyshevFromRoots ¶
NewChebyshevFromRoots builds the monic Chebyshev series with the given roots (numpy Chebyshev.fromroots with default domain).
type Hermite ¶
Hermite is the physicists' Hermite series c[0]*H0 + c[1]*H1 + ... (numpy polynomial.hermite, class Hermite). Default domain and window [-1,1].
func NewHermite ¶
NewHermite builds a Hermite series from coefficients, lowest degree first.
func NewHermiteDomain ¶
NewHermiteDomain is NewHermite with an explicit domain and window.
func NewHermiteFromRoots ¶
NewHermiteFromRoots builds the monic Hermite series with the given roots.
type HermiteE ¶
HermiteE is the probabilists' Hermite series c[0]*He0 + c[1]*He1 + ... (numpy polynomial.hermite_e, class HermiteE). Default domain/window [-1,1].
func NewHermiteE ¶
NewHermiteE builds a probabilists' Hermite series from coefficients.
func NewHermiteEDomain ¶
NewHermiteEDomain is NewHermiteE with an explicit domain and window.
func NewHermiteEFromRoots ¶
NewHermiteEFromRoots builds the monic HermiteE series with the given roots.
type Laguerre ¶
Laguerre is the Laguerre series c[0]*L0 + c[1]*L1 + ... (numpy polynomial.laguerre, class Laguerre). Default domain [0,1], window [-1,1].
func NewLaguerre ¶
NewLaguerre builds a Laguerre series from coefficients, lowest degree first.
func NewLaguerreDomain ¶
NewLaguerreDomain is NewLaguerre with an explicit domain and window.
func NewLaguerreFromRoots ¶
NewLaguerreFromRoots builds the monic Laguerre series with the given roots.
type Legendre ¶
Legendre is the Legendre series c[0]*P0 + c[1]*P1 + ... (numpy polynomial.legendre, class Legendre). Default domain and window [-1,1].
func NewLegendre ¶
NewLegendre builds a Legendre series from coefficients, lowest degree first.
func NewLegendreDomain ¶
NewLegendreDomain is NewLegendre with an explicit domain and window.
func NewLegendreFromRoots ¶
NewLegendreFromRoots builds the monic Legendre series with the given roots.
type Polynomial ¶
Polynomial is the power-basis series c[0] + c[1]*x + ... (numpy polynomial.polynomial, class Polynomial). Default domain and window [-1,1].
func NewPolynomial ¶
func NewPolynomial[T numgo.Float](coef []T) *Polynomial[T]
NewPolynomial builds a power-basis series from coefficients, lowest degree first. The coefficients are copied.
func NewPolynomialDomain ¶
func NewPolynomialDomain[T numgo.Float](coef []T, domain, window [2]T) *Polynomial[T]
NewPolynomialDomain is NewPolynomial with an explicit domain and window.
func NewPolynomialFromRoots ¶
func NewPolynomialFromRoots[T numgo.Float](roots []T) *Polynomial[T]
NewPolynomialFromRoots builds the monic polynomial with the given roots (numpy Polynomial.fromroots with default domain).
func (*Polynomial[T]) Add ¶
func (p *Polynomial[T]) Add(o *Polynomial[T]) *Polynomial[T]
Add returns p + o in the power basis.
func (*Polynomial[T]) Convert ¶
func (p *Polynomial[T]) Convert(domain, window [2]T) *Polynomial[T]
Convert re-parameterizes the same function onto domain/window (numpy convert with kind = self): the converted series' coefficients are the old series composed with the linear map onto the old window.
func (*Polynomial[T]) Copy ¶
func (p *Polynomial[T]) Copy() *Polynomial[T]
Copy returns a deep copy.
func (*Polynomial[T]) Deriv ¶
func (p *Polynomial[T]) Deriv(m int) *Polynomial[T]
Deriv returns the m-th derivative (m >= 1).
func (*Polynomial[T]) Div ¶
func (p *Polynomial[T]) Div(o *Polynomial[T]) (*Polynomial[T], *Polynomial[T])
Div returns the quotient and remainder of p / o (numpy divmod).
func (*Polynomial[T]) Fit ¶
func (p *Polynomial[T]) Fit(x, y *numgo.Array[T], deg int) *Polynomial[T]
Fit least-squares fits degree deg to (x, y), defaulting the domain to [min(x), max(x)] like numpy (ABCPolyBase.fit defaults).
func (*Polynomial[T]) Integ ¶
func (p *Polynomial[T]) Integ(m int, k ...T) *Polynomial[T]
Integ returns the m-th integral with integration constants k (numpy lbnd = 0 convention).
func (*Polynomial[T]) Mul ¶
func (p *Polynomial[T]) Mul(o *Polynomial[T]) *Polynomial[T]
Mul returns the product p * o.
func (*Polynomial[T]) Pow ¶
func (p *Polynomial[T]) Pow(n int) *Polynomial[T]
Pow raises the series to the n-th power.
func (*Polynomial[T]) Sub ¶
func (p *Polynomial[T]) Sub(o *Polynomial[T]) *Polynomial[T]
Sub returns p - o in the power basis.
func (*Polynomial[T]) Trim ¶
func (p *Polynomial[T]) Trim(tol T) *Polynomial[T]
Trim drops trailing coefficients with |c| <= tol.
func (*Polynomial[T]) Truncate ¶
func (p *Polynomial[T]) Truncate(size int) *Polynomial[T]
Truncate drops coefficients beyond the first size.