Struct Polynomial
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§
§impl Polynomial
impl Polynomial
pub 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.
pub fn constant(value: f64) -> Polynomial
pub fn constant(value: f64) -> Polynomial
Creates a constant polynomial.
pub fn zero() -> Polynomial
pub fn zero() -> Polynomial
Creates the zero polynomial.
pub fn one() -> Polynomial
pub fn one() -> Polynomial
Creates the constant polynomial 1.
pub fn coefficients(&self) -> &[f64]
pub fn coefficients(&self) -> &[f64]
Returns the coefficients in ascending power order.
pub const fn degree(&self) -> Option<usize>
pub const fn degree(&self) -> Option<usize>
Returns the polynomial degree, or None for the zero polynomial.
pub fn leading_coefficient(&self) -> Option<f64>
pub fn leading_coefficient(&self) -> Option<f64>
Returns the leading coefficient, or None for the zero polynomial.
pub fn derivative(&self) -> Polynomial
pub fn derivative(&self) -> Polynomial
Returns the derivative of the polynomial.
pub fn nth_derivative(&self, n: usize) -> Polynomial
pub fn nth_derivative(&self, n: usize) -> Polynomial
Returns the nth derivative of the polynomial.
pub fn integral(&self, constant: f64) -> Polynomial
pub fn integral(&self, constant: f64) -> Polynomial
Returns the indefinite integral with the provided constant term.
pub 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§
§impl Add for Polynomial
impl Add for Polynomial
§type Output = Polynomial
type Output = Polynomial
+ operator.§fn add(self, rhs: Polynomial) -> <Polynomial as Add>::Output
fn add(self, rhs: Polynomial) -> <Polynomial as Add>::Output
+ operation. Read more§impl Clone for Polynomial
impl Clone for Polynomial
§fn clone(&self) -> Polynomial
fn clone(&self) -> Polynomial
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for Polynomial
impl Debug for Polynomial
§impl Div<f64> for Polynomial
impl Div<f64> for Polynomial
§impl Mul<f64> for Polynomial
impl Mul<f64> for Polynomial
§impl Mul for Polynomial
impl Mul for Polynomial
§type Output = Polynomial
type Output = Polynomial
* operator.§fn mul(self, rhs: Polynomial) -> <Polynomial as Mul>::Output
fn mul(self, rhs: Polynomial) -> <Polynomial as Mul>::Output
* operation. Read more§impl Neg for Polynomial
impl Neg for Polynomial
§type Output = Polynomial
type Output = Polynomial
- operator.§impl PartialEq for Polynomial
impl PartialEq for Polynomial
§impl Sub for Polynomial
impl Sub for Polynomial
§type Output = Polynomial
type Output = Polynomial
- operator.§fn sub(self, rhs: Polynomial) -> <Polynomial as Sub>::Output
fn sub(self, rhs: Polynomial) -> <Polynomial as Sub>::Output
- operation. Read more