A scalar multi-variate polynomial, modeled after the msspoly in spotless.
Polynomial represents a list of additive Monomials, each one of which is a product of a constant coefficient (of *CoefficientType, which by default is double) and any number of distinct Terms (variables raised to positive integer powers).
Variables are identified by integer indices rather than symbolic names, but an automatic facility is provided to covert variable names up to four characters into unique integers, provided those variables are named using only lowercase letters and the “#*.” characters followed by a number. For example, valid names include “dx4” and “m_x”.
Monomials which have the same variables and powers may be constructed but will be automatically combined: (3 * a * b * a) + (1.5 * b * a**2) will be reduced to (4.5 * b * a**2) internally after construction.
Polynomials can be added, subtracted, and multiplied. They may only be divided by scalars (of _CoefficientType) because Polynomials are not closed under division.
Derivative(self: pydrake.polynomial.Polynomial, derivative_order: int = 1) → pydrake.polynomial.Polynomial¶
Takes the derivative of this (univariate) Polynomial.
Returns a new Polynomial that is the derivative of this one in its sole variable.
Raises: RuntimeError if this Polynomial is not univariate.
If derivative_order is given, takes the nth derivative of this Polynomial.
GetCoefficients(self: pydrake.polynomial.Polynomial) → numpy.ndarray[float64[m, 1]]¶
GetDegree(self: pydrake.polynomial.Polynomial) → int¶
Returns the highest degree of any Monomial in this Polynomial.
The degree of a multivariate Monomial is the product of the degrees of each of its terms.
GetNumberOfCoefficients(self: pydrake.polynomial.Polynomial) → int¶
Returns the number of unique Monomials (and thus the number of coefficients) in this Polynomial.
Integral(self: pydrake.polynomial.Polynomial, integration_constant: float = 0.0) → pydrake.polynomial.Polynomial¶
Takes the integral of this (univariate, non-constant) Polynomial.
Returns a new Polynomial that is the indefinite integral of this one in its sole variable.
- RuntimeError if this Polynomial is not univariate, or if it has no
If integration_constant is given, adds that constant as the constant term (zeroth-order coefficient) of the resulting Polynomial.
IsAffine(self: pydrake.polynomial.Polynomial) → bool¶
Returns true iff this is a sum of terms of degree 1, plus a constant.
IsApprox(self: pydrake.polynomial.Polynomial, other: pydrake.polynomial.Polynomial, tol: float) → bool¶
Checks if a (univariate) Polynomial is approximately equal to this one.
Checks that every coefficient of other is within tol of the corresponding coefficient of this Polynomial.
Raises: RuntimeError if either Polynomial is not univariate.