Struct Function

Source
pub struct Function { /* private fields */ }

Implementations§

Source§

impl Function

Source

pub fn elementary(&self) -> Elementary

Returns the Elementary absraction of the Function instance

Source

pub fn set_function(&mut self, element: Elementary)

Sets the function to represent the provided Elementary abstraction

Source

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.

Source

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.

Source

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.

Source

pub fn get_maclaurin_expansion( &self, order: u8, ) -> Result<SeriesExpansion, Error>

Returns a Maclaurin expansion of the provided order.

Source§

impl Function

Source

pub fn call(&self, x: f64) -> f64

Trait Implementations§

Source§

impl Add<&mut Function> for Function

Source§

type Output = Function

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &mut Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for Function

Source§

type Output = Function

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign for Function

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl Default for Function

Source§

fn default() -> Self

The default() method returns the unit function f(x) = x, returning the independant variable for each input value.

Source§

impl Div<&mut Function> for Function

Source§

type Output = Function

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &mut Self) -> Self::Output

Performs the / operation. Read more
Source§

impl Div for Function

Source§

type Output = Function

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl DivAssign for Function

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl From<&SeriesExpansion> for Function

Source§

fn from(value: &SeriesExpansion) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a String> for Function

Source§

fn from(value: &'a String) -> Self

Converts to this type from the input type.
Source§

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§

fn from(value: &'a str) -> Self

Converts to this type from the input type.
Source§

impl From<Elementary> for Function

Source§

fn from(value: Elementary) -> Self

Converts to this type from the input type.
Source§

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

Converts to this type from the input type.
Source§

impl From<String> for Function

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl Integrate for Function

See Integrate for usage and examples.

Source§

fn integrate(&self) -> Integral

Method will return an instance of Integral that can be taylored to specific usecases. Read more
Source§

fn evaluate_integral(&self, lower_bound: f64, upper_bound: f64) -> f64

Method will return the value of the definite integral of the function evaluated from the provided lower and upper bound. Read more
Source§

impl Mul<&mut Function> for Function

Source§

type Output = Function

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &mut Self) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul for Function

Source§

type Output = Function

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign for Function

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl Sub for Function

Source§

type Output = Function

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl SubAssign for Function

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.