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>) -> Self
pub fn new(coefficients: Vec<f64>) -> Self
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 coefficients(&self) -> &[f64]
pub fn coefficients(&self) -> &[f64]
Returns the coefficients in ascending power order.
Sourcepub const fn degree(&self) -> Option<usize>
pub const 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) -> Self
pub fn derivative(&self) -> Self
Returns the derivative of the polynomial.
Sourcepub fn nth_derivative(&self, n: usize) -> Self
pub fn nth_derivative(&self, n: usize) -> Self
Returns the nth derivative of the polynomial.
Sourcepub fn integral(&self, constant: f64) -> Self
pub fn integral(&self, constant: f64) -> Self
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§impl Clone for Polynomial
impl Clone for Polynomial
Source§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