pub struct Polynomial { /* private fields */ }Expand description
A polynomial whose coefficients are stored in ascending power order.
coefficients[i] is the coefficient for x^i. For example,
3 + 2x + x^2 is represented as vec![3.0, 2.0, 1.0].
The zero polynomial is represented as an empty coefficient vector.
Implementations§
Source§impl Polynomial
impl Polynomial
Sourcepub fn new(coefficients: Vec<f64>) -> Polynomial
pub fn new(coefficients: Vec<f64>) -> Polynomial
Creates a polynomial from coefficients in ascending power order.
Trailing zero coefficients are trimmed. The zero polynomial is stored as an empty coefficient vector.
Sourcepub fn constant(value: f64) -> Polynomial
pub fn constant(value: f64) -> Polynomial
Creates a constant polynomial.
Sourcepub fn zero() -> Polynomial
pub fn zero() -> Polynomial
Creates the zero polynomial.
Sourcepub fn one() -> Polynomial
pub fn one() -> Polynomial
Creates the constant polynomial 1.
Sourcepub fn coefficients(&self) -> &[f64]
pub fn coefficients(&self) -> &[f64]
Returns the coefficients in ascending power order.
Sourcepub fn degree(&self) -> Option<usize>
pub fn degree(&self) -> Option<usize>
Returns the polynomial degree, or None for the zero polynomial.
Sourcepub fn leading_coefficient(&self) -> Option<f64>
pub fn leading_coefficient(&self) -> Option<f64>
Returns the leading coefficient, or None for the zero polynomial.
Sourcepub fn derivative(&self) -> Polynomial
pub fn derivative(&self) -> Polynomial
Returns the derivative of the polynomial.
Sourcepub fn nth_derivative(&self, n: usize) -> Polynomial
pub fn nth_derivative(&self, n: usize) -> Polynomial
Returns the nth derivative of the polynomial.
Sourcepub fn integral(&self, constant: f64) -> Polynomial
pub fn integral(&self, constant: f64) -> Polynomial
Returns the indefinite integral with the provided constant term.
Sourcepub fn real_roots_degree_1_or_2(&self) -> Option<Vec<f64>>
pub fn real_roots_degree_1_or_2(&self) -> Option<Vec<f64>>
Returns real roots for degree 0, 1, or 2 polynomials.
Higher-degree polynomials return None. Constant and zero
polynomials return Some(vec![]).
Trait Implementations§
Source§impl Add for Polynomial
impl Add for Polynomial
Source§type Output = Polynomial
type Output = Polynomial
+ operator.Source§fn add(self, rhs: Polynomial) -> <Polynomial as Add>::Output
fn add(self, rhs: Polynomial) -> <Polynomial as Add>::Output
+ operation. Read moreSource§impl Clone for Polynomial
impl Clone for Polynomial
Source§fn clone(&self) -> Polynomial
fn clone(&self) -> Polynomial
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Polynomial
impl Debug for Polynomial
Source§impl Div<f64> for Polynomial
impl Div<f64> for Polynomial
Source§impl Mul for Polynomial
impl Mul for Polynomial
Source§type Output = Polynomial
type Output = Polynomial
* operator.Source§fn mul(self, rhs: Polynomial) -> <Polynomial as Mul>::Output
fn mul(self, rhs: Polynomial) -> <Polynomial as Mul>::Output
* operation. Read moreSource§impl Mul<f64> for Polynomial
impl Mul<f64> for Polynomial
Source§impl Neg for Polynomial
impl Neg for Polynomial
Source§impl PartialEq for Polynomial
impl PartialEq for Polynomial
impl StructuralPartialEq for Polynomial
Source§impl Sub for Polynomial
impl Sub for Polynomial
Source§type Output = Polynomial
type Output = Polynomial
- operator.Source§fn sub(self, rhs: Polynomial) -> <Polynomial as Sub>::Output
fn sub(self, rhs: Polynomial) -> <Polynomial as Sub>::Output
- operation. Read more