pub struct Function { /* private fields */ }
Implementations§
Source§impl Function
impl Function
Sourcepub fn elementary(&self) -> Elementary
pub fn elementary(&self) -> Elementary
Returns the Elementary absraction of the Function instance
Sourcepub fn set_function(&mut self, element: Elementary)
pub fn set_function(&mut self, element: Elementary)
Sets the function to represent the provided Elementary abstraction
Sourcepub fn differentiate(&mut self)
pub fn differentiate(&mut self)
Turns self into the derivative of self
i.e. f(x) ⟹ f’(x)
Example:
let mut function = Function::from("cosh(x)");
// take derivative
function.differentiate();
// cosh(x)' = sinh(x)
// sinh(0) = 0
assert_eq!(function.call(0.), 0.);
Do also note that differentiating a function will not simplify the result. This is to make sure that this method can never fail, but it does also mean that there are instances where the resulting derivative will return NaN for certain values.
Sourcepub fn as_taylor_expansion(&mut self, order: u8, a: f64) -> Result<(), Error>
pub fn as_taylor_expansion(&mut self, order: u8, a: f64) -> Result<(), Error>
Turns the given Function instance into a Taylor series expansion centered around the value of a.
If the conversion fails, an Error::ExpansionError is returned.
Sourcepub fn get_taylor_expansion(
&self,
order: u8,
a: f64,
) -> Result<SeriesExpansion, Error>
pub fn get_taylor_expansion( &self, order: u8, a: f64, ) -> Result<SeriesExpansion, Error>
Returns a Taylor expansion of the provided order of the function centered around the provided value a.
Sourcepub fn get_maclaurin_expansion(
&self,
order: u8,
) -> Result<SeriesExpansion, Error>
pub fn get_maclaurin_expansion( &self, order: u8, ) -> Result<SeriesExpansion, Error>
Returns a Maclaurin expansion of the provided order.
Trait Implementations§
Source§impl AddAssign for Function
impl AddAssign for Function
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moreSource§impl DivAssign for Function
impl DivAssign for Function
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/=
operation. Read moreSource§impl From<&SeriesExpansion> for Function
impl From<&SeriesExpansion> for Function
Source§fn from(value: &SeriesExpansion) -> Self
fn from(value: &SeriesExpansion) -> Self
Source§impl<'a> From<&'a str> for Function
A Function instance can be parsed from any string type using the from method.
impl<'a> From<&'a str> for Function
A Function instance can be parsed from any string type using the from method.
Example:
let func = Function::from("sin(ln(x))");
assert_eq!(func.call(1.), 0.);
// ...or using the nightly feature
// assert_eq!(func(1.), 0.);
Source§impl From<Elementary> for Function
impl From<Elementary> for Function
Source§fn from(value: Elementary) -> Self
fn from(value: Elementary) -> Self
Source§impl From<SeriesExpansion> for Function
A Function instance can be obtained from a SeriesExpansion instance using the from method.
impl From<SeriesExpansion> for Function
A Function instance can be obtained from a SeriesExpansion instance using the from method.
Example:
// create the Function instance
let func = Function::from("sin(x)");
// Get the SeriesExpansion
// In this instance we're creating a Taylor expansion of order 5 centered around 0
let expansion = func.get_taylor_expansion(5, 0.);
// Convert the SeriesExpansion into a Function using the from method
let func_expansion = Function::from(expansion);
// Note that this could also be done using the get_function method:
// let func_expansion = expansion.get_function()
//
// ... or using the as_taylor_expansion method to convert the original Function instance into a
// Taylor expansion without creating the SeriesExpansion instance seperatly:
// func.as_taylor_expansion()
Source§fn from(value: SeriesExpansion) -> Self
fn from(value: SeriesExpansion) -> Self
Source§impl Integrate for Function
See Integrate for usage and examples.
impl Integrate for Function
See Integrate for usage and examples.
Source§impl MulAssign for Function
impl MulAssign for Function
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moreAuto Trait Implementations§
impl Freeze for Function
impl RefUnwindSafe for Function
impl Send for Function
impl Sync for Function
impl Unpin for Function
impl UnwindSafe for Function
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more