pub struct Term<const NUM_VARIABLES: usize> { /* private fields */ }Expand description
Represents a single term in a polynomial with NUM_VARIABLES variables.
A term consists of a coefficient and an array of VarFunctions, each
applied to a corresponding variable in the input.
For example, for NUM_VARIABLES = 2:
use const_poly::{Term, VarFunction::*};
const TERM: Term<2> = Term::new(3.0, [Sin, Pow(2)]);represents the term 3 * sin(x_0) * (x_1)^2.
Implementations§
Source§impl<const NUM_VARIABLES: usize> Term<NUM_VARIABLES>
impl<const NUM_VARIABLES: usize> Term<NUM_VARIABLES>
Sourcepub const fn new(
coefficient: f64,
functions: [VarFunction; NUM_VARIABLES],
) -> Self
pub const fn new( coefficient: f64, functions: [VarFunction; NUM_VARIABLES], ) -> Self
Creates a new Term with the specified coefficient and functions.
§Parameters
coefficient: The scalar multiplier for the term.functions: An array ofVarFunctions, one per variable.
§Returns
A new Term instance.
§Example
use const_poly::{Term, VarFunction::*};
const TERM: Term<2> = Term::new(2.0, [Sin, Pow(3)]);represents the term 2.0 * sin(x_0) * (x_1)^3.
Sourcepub const fn evaluate(&self, vars: [f64; NUM_VARIABLES]) -> f64
pub const fn evaluate(&self, vars: [f64; NUM_VARIABLES]) -> f64
Evaluates the term for the given variables.
Applies each function in functions to the corresponding variable,
then multiplies all results together with the coefficient.
§Parameters
vars: An array of variables of lengthNUM_VARIABLES.
§Returns
The floating-point result of evaluating the term.
§Example
use const_poly::{Term, VarFunction::*};
const TERM: Term<1> = Term::new(2.0, [Sin]);
const val: f64 = TERM.evaluate([1.57079632679]); // Approx sin(pi/2)
assert!((val - 2.0).abs() < 1e-6);Trait Implementations§
impl<const NUM_VARIABLES: usize> Copy for Term<NUM_VARIABLES>
Auto Trait Implementations§
impl<const NUM_VARIABLES: usize> Freeze for Term<NUM_VARIABLES>
impl<const NUM_VARIABLES: usize> RefUnwindSafe for Term<NUM_VARIABLES>
impl<const NUM_VARIABLES: usize> Send for Term<NUM_VARIABLES>
impl<const NUM_VARIABLES: usize> Sync for Term<NUM_VARIABLES>
impl<const NUM_VARIABLES: usize> Unpin for Term<NUM_VARIABLES>
impl<const NUM_VARIABLES: usize> UnwindSafe for Term<NUM_VARIABLES>
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