polynomial

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base[T numgo.Float] struct {
	// contains filtered or unexported fields
}

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]) BasisName

func (b Base[T]) BasisName() string

BasisName returns the class basis name.

func (Base[T]) Call

func (b Base[T]) Call(x *numgo.Array[T]) *numgo.Array[T]

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]) Companion

func (b Base[T]) Companion() *numgo.Array[T]

Companion returns the companion matrix of the series.

func (Base[T]) Domain

func (b Base[T]) Domain() [2]T

Domain returns the domain interval the argument is mapped from.

func (Base[T]) Len

func (b Base[T]) Len() int

Len returns the number of coefficients.

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]) String

func (b Base[T]) String() string

String renders "Chebyshev([1,2], domain=[0,1], window=[-1,1])".

func (Base[T]) Val

func (b Base[T]) Val(x *numgo.Array[T]) *numgo.Array[T]

Val evaluates the series at each element of x, which must already be in window coordinates. The input shape is preserved.

func (Base[T]) Vander

func (b Base[T]) Vander(x *numgo.Array[T], deg int) *numgo.Array[T]

Vander returns the (len(x), deg+1) pseudo-Vandermonde matrix in this class basis at the window-coordinate points x.

func (Base[T]) Window

func (b Base[T]) Window() [2]T

Window returns the window interval the basis is defined on.

type Chebyshev

type Chebyshev[T numgo.Float] struct{ Base[T] }

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

func NewChebyshev[T numgo.Float](coef []T) *Chebyshev[T]

NewChebyshev builds a Chebyshev series from coefficients, lowest degree first. The coefficients are copied.

func NewChebyshevDomain

func NewChebyshevDomain[T numgo.Float](coef []T, domain, window [2]T) *Chebyshev[T]

NewChebyshevDomain is NewChebyshev with an explicit domain and window.

func NewChebyshevFromRoots

func NewChebyshevFromRoots[T numgo.Float](roots []T) *Chebyshev[T]

NewChebyshevFromRoots builds the monic Chebyshev series with the given roots (numpy Chebyshev.fromroots with default domain).

func (*Chebyshev[T]) Add

func (c *Chebyshev[T]) Add(o *Chebyshev[T]) *Chebyshev[T]

Add returns c + o in the Chebyshev basis.

func (*Chebyshev[T]) Convert

func (c *Chebyshev[T]) Convert(domain, window [2]T) *Chebyshev[T]

Convert re-parameterizes the same function onto domain/window.

func (*Chebyshev[T]) Copy

func (c *Chebyshev[T]) Copy() *Chebyshev[T]

Copy returns a deep copy.

func (*Chebyshev[T]) Deriv

func (c *Chebyshev[T]) Deriv(m int) *Chebyshev[T]

Deriv returns the m-th derivative (m >= 1).

func (*Chebyshev[T]) Div

func (c *Chebyshev[T]) Div(o *Chebyshev[T]) (*Chebyshev[T], *Chebyshev[T])

Div returns the quotient and remainder of c / o.

func (*Chebyshev[T]) Fit

func (c *Chebyshev[T]) Fit(x, y *numgo.Array[T], deg int) *Chebyshev[T]

Fit least-squares fits degree deg to (x, y) with numpy default domain.

func (*Chebyshev[T]) Integ

func (c *Chebyshev[T]) Integ(m int, k ...T) *Chebyshev[T]

Integ returns the m-th integral with integration constants k.

func (*Chebyshev[T]) Mul

func (c *Chebyshev[T]) Mul(o *Chebyshev[T]) *Chebyshev[T]

Mul returns the Chebyshev product.

func (*Chebyshev[T]) Pow

func (c *Chebyshev[T]) Pow(n int) *Chebyshev[T]

Pow raises the series to the n-th power.

func (*Chebyshev[T]) Sub

func (c *Chebyshev[T]) Sub(o *Chebyshev[T]) *Chebyshev[T]

Sub returns c - o in the Chebyshev basis.

func (*Chebyshev[T]) Trim

func (c *Chebyshev[T]) Trim(tol T) *Chebyshev[T]

Trim drops trailing coefficients with |c| <= tol.

func (*Chebyshev[T]) Truncate

func (c *Chebyshev[T]) Truncate(size int) *Chebyshev[T]

Truncate drops coefficients beyond the first size.

type Hermite

type Hermite[T numgo.Float] struct{ Base[T] }

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

func NewHermite[T numgo.Float](coef []T) *Hermite[T]

NewHermite builds a Hermite series from coefficients, lowest degree first.

func NewHermiteDomain

func NewHermiteDomain[T numgo.Float](coef []T, domain, window [2]T) *Hermite[T]

NewHermiteDomain is NewHermite with an explicit domain and window.

func NewHermiteFromRoots

func NewHermiteFromRoots[T numgo.Float](roots []T) *Hermite[T]

NewHermiteFromRoots builds the monic Hermite series with the given roots.

func (*Hermite[T]) Add

func (h *Hermite[T]) Add(o *Hermite[T]) *Hermite[T]

Add returns h + o in the Hermite basis.

func (*Hermite[T]) Convert

func (h *Hermite[T]) Convert(domain, window [2]T) *Hermite[T]

Convert re-parameterizes the same function onto domain/window.

func (*Hermite[T]) Copy

func (h *Hermite[T]) Copy() *Hermite[T]

Copy returns a deep copy.

func (*Hermite[T]) Deriv

func (h *Hermite[T]) Deriv(m int) *Hermite[T]

Deriv returns the m-th derivative (m >= 1).

func (*Hermite[T]) Div

func (h *Hermite[T]) Div(o *Hermite[T]) (*Hermite[T], *Hermite[T])

Div returns the quotient and remainder of h / o.

func (*Hermite[T]) Fit

func (h *Hermite[T]) Fit(x, y *numgo.Array[T], deg int) *Hermite[T]

Fit least-squares fits degree deg to (x, y) with numpy default domain.

func (*Hermite[T]) Integ

func (h *Hermite[T]) Integ(m int, k ...T) *Hermite[T]

Integ returns the m-th integral with integration constants k.

func (*Hermite[T]) Mul

func (h *Hermite[T]) Mul(o *Hermite[T]) *Hermite[T]

Mul returns the Hermite product.

func (*Hermite[T]) Pow

func (h *Hermite[T]) Pow(n int) *Hermite[T]

Pow raises the series to the n-th power.

func (*Hermite[T]) Sub

func (h *Hermite[T]) Sub(o *Hermite[T]) *Hermite[T]

Sub returns h - o in the Hermite basis.

func (*Hermite[T]) Trim

func (h *Hermite[T]) Trim(tol T) *Hermite[T]

Trim drops trailing coefficients with |c| <= tol.

func (*Hermite[T]) Truncate

func (h *Hermite[T]) Truncate(size int) *Hermite[T]

Truncate drops coefficients beyond the first size.

type HermiteE

type HermiteE[T numgo.Float] struct{ Base[T] }

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

func NewHermiteE[T numgo.Float](coef []T) *HermiteE[T]

NewHermiteE builds a probabilists' Hermite series from coefficients.

func NewHermiteEDomain

func NewHermiteEDomain[T numgo.Float](coef []T, domain, window [2]T) *HermiteE[T]

NewHermiteEDomain is NewHermiteE with an explicit domain and window.

func NewHermiteEFromRoots

func NewHermiteEFromRoots[T numgo.Float](roots []T) *HermiteE[T]

NewHermiteEFromRoots builds the monic HermiteE series with the given roots.

func (*HermiteE[T]) Add

func (h *HermiteE[T]) Add(o *HermiteE[T]) *HermiteE[T]

Add returns h + o in the HermiteE basis.

func (*HermiteE[T]) Convert

func (h *HermiteE[T]) Convert(domain, window [2]T) *HermiteE[T]

Convert re-parameterizes the same function onto domain/window.

func (*HermiteE[T]) Copy

func (h *HermiteE[T]) Copy() *HermiteE[T]

Copy returns a deep copy.

func (*HermiteE[T]) Deriv

func (h *HermiteE[T]) Deriv(m int) *HermiteE[T]

Deriv returns the m-th derivative (m >= 1).

func (*HermiteE[T]) Div

func (h *HermiteE[T]) Div(o *HermiteE[T]) (*HermiteE[T], *HermiteE[T])

Div returns the quotient and remainder of h / o.

func (*HermiteE[T]) Fit

func (h *HermiteE[T]) Fit(x, y *numgo.Array[T], deg int) *HermiteE[T]

Fit least-squares fits degree deg to (x, y) with numpy default domain.

func (*HermiteE[T]) Integ

func (h *HermiteE[T]) Integ(m int, k ...T) *HermiteE[T]

Integ returns the m-th integral with integration constants k.

func (*HermiteE[T]) Mul

func (h *HermiteE[T]) Mul(o *HermiteE[T]) *HermiteE[T]

Mul returns the HermiteE product.

func (*HermiteE[T]) Pow

func (h *HermiteE[T]) Pow(n int) *HermiteE[T]

Pow raises the series to the n-th power.

func (*HermiteE[T]) Sub

func (h *HermiteE[T]) Sub(o *HermiteE[T]) *HermiteE[T]

Sub returns h - o in the HermiteE basis.

func (*HermiteE[T]) Trim

func (h *HermiteE[T]) Trim(tol T) *HermiteE[T]

Trim drops trailing coefficients with |c| <= tol.

func (*HermiteE[T]) Truncate

func (h *HermiteE[T]) Truncate(size int) *HermiteE[T]

Truncate drops coefficients beyond the first size.

type Laguerre

type Laguerre[T numgo.Float] struct{ Base[T] }

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

func NewLaguerre[T numgo.Float](coef []T) *Laguerre[T]

NewLaguerre builds a Laguerre series from coefficients, lowest degree first.

func NewLaguerreDomain

func NewLaguerreDomain[T numgo.Float](coef []T, domain, window [2]T) *Laguerre[T]

NewLaguerreDomain is NewLaguerre with an explicit domain and window.

func NewLaguerreFromRoots

func NewLaguerreFromRoots[T numgo.Float](roots []T) *Laguerre[T]

NewLaguerreFromRoots builds the monic Laguerre series with the given roots.

func (*Laguerre[T]) Add

func (l *Laguerre[T]) Add(o *Laguerre[T]) *Laguerre[T]

Add returns l + o in the Laguerre basis.

func (*Laguerre[T]) Convert

func (l *Laguerre[T]) Convert(domain, window [2]T) *Laguerre[T]

Convert re-parameterizes the same function onto domain/window.

func (*Laguerre[T]) Copy

func (l *Laguerre[T]) Copy() *Laguerre[T]

Copy returns a deep copy.

func (*Laguerre[T]) Deriv

func (l *Laguerre[T]) Deriv(m int) *Laguerre[T]

Deriv returns the m-th derivative (m >= 1).

func (*Laguerre[T]) Div

func (l *Laguerre[T]) Div(o *Laguerre[T]) (*Laguerre[T], *Laguerre[T])

Div returns the quotient and remainder of l / o.

func (*Laguerre[T]) Fit

func (l *Laguerre[T]) Fit(x, y *numgo.Array[T], deg int) *Laguerre[T]

Fit least-squares fits degree deg to (x, y) with numpy default domain.

func (*Laguerre[T]) Integ

func (l *Laguerre[T]) Integ(m int, k ...T) *Laguerre[T]

Integ returns the m-th integral with integration constants k.

func (*Laguerre[T]) Mul

func (l *Laguerre[T]) Mul(o *Laguerre[T]) *Laguerre[T]

Mul returns the Laguerre product.

func (*Laguerre[T]) Pow

func (l *Laguerre[T]) Pow(n int) *Laguerre[T]

Pow raises the series to the n-th power.

func (*Laguerre[T]) Sub

func (l *Laguerre[T]) Sub(o *Laguerre[T]) *Laguerre[T]

Sub returns l - o in the Laguerre basis.

func (*Laguerre[T]) Trim

func (l *Laguerre[T]) Trim(tol T) *Laguerre[T]

Trim drops trailing coefficients with |c| <= tol.

func (*Laguerre[T]) Truncate

func (l *Laguerre[T]) Truncate(size int) *Laguerre[T]

Truncate drops coefficients beyond the first size.

type Legendre

type Legendre[T numgo.Float] struct{ Base[T] }

Legendre is the Legendre series c[0]*P0 + c[1]*P1 + ... (numpy polynomial.legendre, class Legendre). Default domain and window [-1,1].

func NewLegendre

func NewLegendre[T numgo.Float](coef []T) *Legendre[T]

NewLegendre builds a Legendre series from coefficients, lowest degree first.

func NewLegendreDomain

func NewLegendreDomain[T numgo.Float](coef []T, domain, window [2]T) *Legendre[T]

NewLegendreDomain is NewLegendre with an explicit domain and window.

func NewLegendreFromRoots

func NewLegendreFromRoots[T numgo.Float](roots []T) *Legendre[T]

NewLegendreFromRoots builds the monic Legendre series with the given roots.

func (*Legendre[T]) Add

func (l *Legendre[T]) Add(o *Legendre[T]) *Legendre[T]

Add returns l + o in the Legendre basis.

func (*Legendre[T]) Convert

func (l *Legendre[T]) Convert(domain, window [2]T) *Legendre[T]

Convert re-parameterizes the same function onto domain/window.

func (*Legendre[T]) Copy

func (l *Legendre[T]) Copy() *Legendre[T]

Copy returns a deep copy.

func (*Legendre[T]) Deriv

func (l *Legendre[T]) Deriv(m int) *Legendre[T]

Deriv returns the m-th derivative (m >= 1).

func (*Legendre[T]) Div

func (l *Legendre[T]) Div(o *Legendre[T]) (*Legendre[T], *Legendre[T])

Div returns the quotient and remainder of l / o.

func (*Legendre[T]) Fit

func (l *Legendre[T]) Fit(x, y *numgo.Array[T], deg int) *Legendre[T]

Fit least-squares fits degree deg to (x, y) with numpy default domain.

func (*Legendre[T]) Integ

func (l *Legendre[T]) Integ(m int, k ...T) *Legendre[T]

Integ returns the m-th integral with integration constants k.

func (*Legendre[T]) Mul

func (l *Legendre[T]) Mul(o *Legendre[T]) *Legendre[T]

Mul returns the Legendre product.

func (*Legendre[T]) Pow

func (l *Legendre[T]) Pow(n int) *Legendre[T]

Pow raises the series to the n-th power.

func (*Legendre[T]) Sub

func (l *Legendre[T]) Sub(o *Legendre[T]) *Legendre[T]

Sub returns l - o in the Legendre basis.

func (*Legendre[T]) Trim

func (l *Legendre[T]) Trim(tol T) *Legendre[T]

Trim drops trailing coefficients with |c| <= tol.

func (*Legendre[T]) Truncate

func (l *Legendre[T]) Truncate(size int) *Legendre[T]

Truncate drops coefficients beyond the first size.

type Polynomial

type Polynomial[T numgo.Float] struct{ Base[T] }

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL