Polynomials (polynomial)#
The polynomial module provides classes and functions for polynomial operations.
Example#
import numpycore as np
# Create polynomial: 1 + 2x + 3x^2
p = np.polynomial.Polynomial([1, 2, 3])
# Evaluate at x = 2
print(p(2)) # 17.0
# Polynomial arithmetic
q = np.polynomial.Polynomial([1, 1])
print(p + q) # Add polynomials
print(p * q) # Multiply polynomials
# Polynomial fitting
x = np.array([0, 1, 2, 3, 4])
y = np.array([0, 1, 4, 9, 16])
coeffs = np.polyfit(x, y, 2)
Polynomial Class#
Method |
Description |
|---|---|
Polynomial(coef) |
Create polynomial from coefficients |
__call__(x) |
Evaluate polynomial at x |
deriv(m=1) |
Derivative of polynomial |
integ(m=1) |
Indefinite integral |
roots() |
Polynomial roots |
fit(x, y, deg) |
Least squares fit |
Polynomial Functions#
Function |
Description |
|---|---|
polyval(x, c) |
Evaluate polynomial at points x |
polyfit(x, y, deg) |
Least squares polynomial fit |
polyadd(c1, c2) |
Add two polynomials |
polysub(c1, c2) |
Subtract two polynomials |
polymul(c1, c2) |
Multiply two polynomials |
polydiv(c1, c2) |
Divide two polynomials |
polyder(c) |
Polynomial derivative |
polyint(c) |
Polynomial integral |
polyroots(c) |
Roots of polynomial |
Special Polynomials#
Class |
Description |
|---|---|
Chebyshev |
Chebyshev polynomials |
Legendre |
Legendre polynomials |
Hermite |
Hermite polynomials (physicist’s) |
HermiteE |
Hermite polynomials (probabilist’s) |
Laguerre |
Laguerre polynomials |