[−][src]Struct polynom::polynomial::Polynomial
A simple polynomial representation with coefficients
and an indeterminate
.
Fields
coefficients: Vec<f64>
Coefficients of Polynomial. The index of each coefficient indicates its degree, for example in vec![1, 2]
, the first value is explicitly 1x^0
, the second is 2x^1
, etc.
indeterminate: char
The char
representation of the indeterminate, eg. f(x) = 1 + 2x
Methods
impl Polynomial
[src]
pub fn new(coefficients: Vec<f64>, indeterminate: char) -> Polynomial
[src]
Returns a Polynomial from a vector of floats and an indeterminate
Example
use polynom::polynomial::Polynomial; let polynomial = Polynomial::new(vec![1f64, 2f64, 3f64], 'x'); assert_eq!(polynomial.coefficients, vec![1f64, 2f64, 3f64]);
pub fn from_ints(coefficients: Vec<i64>, indeterminate: char) -> Polynomial
[src]
Returns a Polynomial from a vector of integers and an indeterminate
Example
use polynom::polynomial::Polynomial; let polynomial = Polynomial::from_ints(vec![1, 2, 3], 'x'); assert_eq!(polynomial.coefficients, vec![1f64, 2f64, 3f64]);
pub fn add(&self, other: Polynomial) -> Polynomial
[src]
Adds the same-degree coefficients of other: Polynomial
to the coefficients of self
, and returns a new Polynomial with the summed coefficients.
Example
use polynom::polynomial::Polynomial; let a_polynomial = Polynomial::from_ints(vec![1, 2, 3], 'x'); let b_polynomial = Polynomial::from_ints(vec![1, 2, 3], 'x'); assert_eq!(a_polynomial.add(b_polynomial).coefficients, vec![2f64, 4f64, 6f64]);
pub fn sub(&self, other: Polynomial) -> Polynomial
[src]
Adds the same-degree coefficients of other: Polynomial
to the coefficients of self
, and returns a new Polynomial with the summed coefficients.
Example
use polynom::polynomial::Polynomial; let a_polynomial = Polynomial::from_ints(vec![1, 2], 'x'); let b_polynomial = Polynomial::from_ints(vec![2, 4], 'x'); assert_eq!(a_polynomial.sub(b_polynomial).coefficients, vec![-1f64, -2f64]);
pub fn multiply(&self, other: Polynomial) -> Polynomial
[src]
Multiplies the same-degree coefficients of self
and other
, and returns a Polynomial with the new coefficients.
Example
use polynom::polynomial::Polynomial; let a_polynomial = Polynomial::from_ints(vec![1, 2], 'x'); let b_polynomial = Polynomial::from_ints(vec![2, 4], 'x'); assert_eq!(a_polynomial.multiply(b_polynomial).coefficients, vec![2f64, 8f64, 8f64]);
pub fn evaluate_at(&self, determinate: f64) -> f64
[src]
Return the result of evaluating a Polynomial at value determinate
Example
use polynom::polynomial::Polynomial; let polynomial = Polynomial::new(vec![1f64, 2f64, 3f64], 'x'); assert_eq!(polynomial.evaluate_at(1.0), 6f64)
pub fn as_string(&self) -> String
[src]
Return the polynomial represented as a String
Example
use polynom::polynomial::Polynomial; let polynomial = Polynomial::new(vec![1f64, 2f64, 3f64], 'x'); assert_eq!(polynomial.as_string(), String::from("f(x) = 1 + 2x + 3x^2"))
pub fn degree(&self) -> isize
[src]
Return an integer representation of the degree of the Polynomial
Example
use polynom::polynomial::Polynomial; let polynomial = Polynomial::new(vec![1f64, 2f64, 3f64], 'x'); assert_eq!(polynomial.degree(), 2)
Trait Implementations
Auto Trait Implementations
impl Send for Polynomial
impl Unpin for Polynomial
impl Sync for Polynomial
impl RefUnwindSafe for Polynomial
impl UnwindSafe for Polynomial
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,