pub struct Polynomial {
pub coefs: ColVec,
pub deg: usize,
}Expand description
Use Polynomial to implement RealValuedFunction when the coefficients of a polynomial is given.
- There is no performance difference between
Polynomial::ats_incr()andPolynomial::ats(). - The
coefsis the coefficients of a polynomial. For example,coefs=[a2, a1, a0]means the quadratic polynomiala2 x^2 + a1 x + a0. Polynomial::deriv()gives the derivative of the polynomial.Polynomial::from_interp()interpolates data and return a polynomial. Do not use it for 7-or-more-degree polynomials. It is numerically unstable. UseBarycentricPolynomialwhenever possible.
§Examples
use ndarray::prelude::*;
use te1d::prelude::*;
use te1d::func::Polynomial;
// create a new polynomial
let f = Polynomial::new(&array![1.5, -1.2, 0.5, 0.7]);
let result = f.ats(&array![-1.0, -0.5, 0.0, 0.3, 0.9]);
let sol = array![-2.5, -0.0375, 0.7, 0.7825, 1.2715];
assert!(all_close(&result, &sol, 1e-05, 1e-08));
assert!(is_close(f.at(0.75), 1.0328125, 1e-05, 1e-08));
assert_eq!(&result, &f.ats_incr(&array![-1.0, -0.5, 0.0, 0.3, 0.9]));
// find the derivative
let deriv = f.deriv();
assert_eq!(&deriv, &Polynomial::new(&array![4.5, -2.4, 0.5]));
// polynomial interpolation
let xs: ColVec = array![0.0, 0.5, 2.5, 3.0];
let fs: ColVec = array![1.0, 0.0, 2.0, 3.0];
let f = Polynomial::from_interp(&xs, &fs).unwrap();
assert!(all_close(&f.ats(&xs), &fs, 1e-05, 1e-08));
assert_eq!(f.deg, 3);Fields§
§coefs: ColVecThe coefficients of the polynomial.
deg: usizeThe degree of the polynomial.
Implementations§
Source§impl Polynomial
impl Polynomial
Trait Implementations§
Source§impl Clone for Polynomial
impl Clone for Polynomial
Source§fn clone(&self) -> Polynomial
fn clone(&self) -> Polynomial
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Polynomial
impl Debug for Polynomial
Source§impl PartialEq for Polynomial
impl PartialEq for Polynomial
Source§impl RealValuedFunction for Polynomial
impl RealValuedFunction for Polynomial
impl StructuralPartialEq for Polynomial
Auto Trait Implementations§
impl Freeze for Polynomial
impl RefUnwindSafe for Polynomial
impl Send for Polynomial
impl Sync for Polynomial
impl Unpin for Polynomial
impl UnwindSafe for Polynomial
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more