pydrake.polynomial
- class pydrake.polynomial.Polynomial
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 T, 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 convert 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 T) because Polynomials are not closed under division.
Note
This class is templated; see
Polynomial_
for the list of instantiations.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pydrake.polynomial.Polynomial) -> None
Construct the vacuous polynomial, “0”.
__init__(self: pydrake.polynomial.Polynomial, arg0: float) -> None
Construct a Polynomial of a single constant. e.g. “5”.
__init__(self: pydrake.polynomial.Polynomial, coefficients: numpy.ndarray[numpy.float64[m, 1]]) -> None
A constructor for univariate polynomials: takes a vector of coefficients for the x**0, x**1, x**2, x**3… Monomials. All terms are always added, even if a coefficient is zero.
- CoefficientsAlmostEqual(self: pydrake.polynomial.Polynomial, other: pydrake.polynomial.Polynomial, tol: float = 0.0, tol_type: pydrake.common.ToleranceType = <ToleranceType.kAbsolute: 0>) bool
Checks if a Polynomial is approximately equal to this one.
Checks that every coefficient of
other
is withintol
of the corresponding coefficient of this Polynomial.Note: When
tol_type
is kRelative, if any monomials appear inthis
orother
but not both, then the method returns false (since the comparison is relative to a missing zero coefficient). Use kAbsolute if you want to ignore non-matching monomials with coefficients less thantol
.
- 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.
- EvaluateUnivariate(self: pydrake.polynomial.Polynomial, x: float, derivative_order: int = 0) float
Evaluate a univariate Polynomial at a specific point.
Evaluates a univariate Polynomial at the given x.
- Raises
RuntimeError if this Polynomial is not univariate. –
x
may be of any type supporting the ** and + operations (which can be different from both CoefficientsType and RealScalar).This method may also be used for efficient evaluation of the derivatives of the univariate polynomial, evaluated at
x
.derivative_order
= 0 (the default) returns the polynomial value without differentiation.derivative_order
= 1 returns the first derivative, etc.- Precondition:
derivative_order must be non-negative.
- GetCoefficients(self: pydrake.polynomial.Polynomial) numpy.ndarray[numpy.float64[m, 1]]
Returns the vector of the coefficients of the polynomial in the order of powers of the variable - the [i]th element is the coefficient of the variable raised to the ith power.
- Raises
RuntimeError if this Polynomial is not univariate. –
- 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.
- Raises
RuntimeError if this Polynomial is not univariate, or if it has no –
variables. –
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.
- template pydrake.polynomial.Polynomial_
Instantiations:
Polynomial_[float]
,Polynomial_[AutoDiffXd]
,Polynomial_[Expression]
- class pydrake.polynomial.Polynomial_[AutoDiffXd]
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 T, 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 convert 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 T) because Polynomials are not closed under division.
- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pydrake.polynomial.Polynomial_[AutoDiffXd]) -> None
Construct the vacuous polynomial, “0”.
__init__(self: pydrake.polynomial.Polynomial_[AutoDiffXd], arg0: pydrake.autodiffutils.AutoDiffXd) -> None
Construct a Polynomial of a single constant. e.g. “5”.
__init__(self: pydrake.polynomial.Polynomial_[AutoDiffXd], coefficients: numpy.ndarray[numpy.float64[m, 1]]) -> None
A constructor for univariate polynomials: takes a vector of coefficients for the x**0, x**1, x**2, x**3… Monomials. All terms are always added, even if a coefficient is zero.
- CoefficientsAlmostEqual(self: pydrake.polynomial.Polynomial_[AutoDiffXd], other: pydrake.polynomial.Polynomial_[AutoDiffXd], tol: pydrake.autodiffutils.AutoDiffXd = 0.0, tol_type: pydrake.common.ToleranceType = <ToleranceType.kAbsolute: 0>) bool
Checks if a Polynomial is approximately equal to this one.
Checks that every coefficient of
other
is withintol
of the corresponding coefficient of this Polynomial.Note: When
tol_type
is kRelative, if any monomials appear inthis
orother
but not both, then the method returns false (since the comparison is relative to a missing zero coefficient). Use kAbsolute if you want to ignore non-matching monomials with coefficients less thantol
.
- Derivative(self: pydrake.polynomial.Polynomial_[AutoDiffXd], derivative_order: int = 1) pydrake.polynomial.Polynomial_[AutoDiffXd]
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.
- EvaluateUnivariate(self: pydrake.polynomial.Polynomial_[AutoDiffXd], x: pydrake.autodiffutils.AutoDiffXd, derivative_order: int = 0) pydrake.autodiffutils.AutoDiffXd
Evaluate a univariate Polynomial at a specific point.
Evaluates a univariate Polynomial at the given x.
- Raises
RuntimeError if this Polynomial is not univariate. –
x
may be of any type supporting the ** and + operations (which can be different from both CoefficientsType and RealScalar).This method may also be used for efficient evaluation of the derivatives of the univariate polynomial, evaluated at
x
.derivative_order
= 0 (the default) returns the polynomial value without differentiation.derivative_order
= 1 returns the first derivative, etc.- Precondition:
derivative_order must be non-negative.
- GetCoefficients(self: pydrake.polynomial.Polynomial_[AutoDiffXd]) numpy.ndarray[object[m, 1]]
Returns the vector of the coefficients of the polynomial in the order of powers of the variable - the [i]th element is the coefficient of the variable raised to the ith power.
- Raises
RuntimeError if this Polynomial is not univariate. –
- GetDegree(self: pydrake.polynomial.Polynomial_[AutoDiffXd]) 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_[AutoDiffXd]) int
Returns the number of unique Monomials (and thus the number of coefficients) in this Polynomial.
- Integral(self: pydrake.polynomial.Polynomial_[AutoDiffXd], integration_constant: pydrake.autodiffutils.AutoDiffXd = 0.0) pydrake.polynomial.Polynomial_[AutoDiffXd]
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.
- Raises
RuntimeError if this Polynomial is not univariate, or if it has no –
variables. –
If integration_constant is given, adds that constant as the constant term (zeroth-order coefficient) of the resulting Polynomial.
- IsAffine(self: pydrake.polynomial.Polynomial_[AutoDiffXd]) bool
Returns true iff this is a sum of terms of degree 1, plus a constant.
- class pydrake.polynomial.Polynomial_[Expression]
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 T, 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 convert 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 T) because Polynomials are not closed under division.
- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pydrake.polynomial.Polynomial_[Expression]) -> None
Construct the vacuous polynomial, “0”.
__init__(self: pydrake.polynomial.Polynomial_[Expression], arg0: pydrake.symbolic.Expression) -> None
Construct a Polynomial of a single constant. e.g. “5”.
__init__(self: pydrake.polynomial.Polynomial_[Expression], coefficients: numpy.ndarray[numpy.float64[m, 1]]) -> None
A constructor for univariate polynomials: takes a vector of coefficients for the x**0, x**1, x**2, x**3… Monomials. All terms are always added, even if a coefficient is zero.
- CoefficientsAlmostEqual(self: pydrake.polynomial.Polynomial_[Expression], other: pydrake.polynomial.Polynomial_[Expression], tol: pydrake.symbolic.Expression = 0.0, tol_type: pydrake.common.ToleranceType = <ToleranceType.kAbsolute: 0>) pydrake.symbolic.Formula
Checks if a Polynomial is approximately equal to this one.
Checks that every coefficient of
other
is withintol
of the corresponding coefficient of this Polynomial.Note: When
tol_type
is kRelative, if any monomials appear inthis
orother
but not both, then the method returns false (since the comparison is relative to a missing zero coefficient). Use kAbsolute if you want to ignore non-matching monomials with coefficients less thantol
.
- Derivative(self: pydrake.polynomial.Polynomial_[Expression], derivative_order: int = 1) pydrake.polynomial.Polynomial_[Expression]
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.
- EvaluateUnivariate(self: pydrake.polynomial.Polynomial_[Expression], x: pydrake.symbolic.Expression, derivative_order: int = 0) pydrake.symbolic.Expression
Evaluate a univariate Polynomial at a specific point.
Evaluates a univariate Polynomial at the given x.
- Raises
RuntimeError if this Polynomial is not univariate. –
x
may be of any type supporting the ** and + operations (which can be different from both CoefficientsType and RealScalar).This method may also be used for efficient evaluation of the derivatives of the univariate polynomial, evaluated at
x
.derivative_order
= 0 (the default) returns the polynomial value without differentiation.derivative_order
= 1 returns the first derivative, etc.- Precondition:
derivative_order must be non-negative.
- GetCoefficients(self: pydrake.polynomial.Polynomial_[Expression]) numpy.ndarray[object[m, 1]]
Returns the vector of the coefficients of the polynomial in the order of powers of the variable - the [i]th element is the coefficient of the variable raised to the ith power.
- Raises
RuntimeError if this Polynomial is not univariate. –
- GetDegree(self: pydrake.polynomial.Polynomial_[Expression]) 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_[Expression]) int
Returns the number of unique Monomials (and thus the number of coefficients) in this Polynomial.
- Integral(self: pydrake.polynomial.Polynomial_[Expression], integration_constant: pydrake.symbolic.Expression = 0.0) pydrake.polynomial.Polynomial_[Expression]
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.
- Raises
RuntimeError if this Polynomial is not univariate, or if it has no –
variables. –
If integration_constant is given, adds that constant as the constant term (zeroth-order coefficient) of the resulting Polynomial.
- IsAffine(self: pydrake.polynomial.Polynomial_[Expression]) bool
Returns true iff this is a sum of terms of degree 1, plus a constant.