Struct F2D

Source
pub struct F2D(/* private fields */);
Expand description

Representation of a 2D function

Implementations§

Source§

impl F2D

Source

pub fn derive(&self, var: char, order: usize) -> Self

Computes the nth-derivative

use ruut_functions::{f2d,F2D};
assert_eq!(f2d!("x+y^2").derive('y', 2), f2d!("2"));
Source

pub fn gradient(&self) -> Vec<Self>

Computes the gradient

use ruut_functions::{f2d, F2D};
assert_eq!(f2d!("x+y^2").gradient(), vec![f2d!("1"), f2d!("2y")]);
Source

pub fn hessian(&self) -> Vec<Vec<Self>>

Computes the hessian matrix

use ruut_functions::{f2d, F2D};
let f = f2d!("x^3+y^2");
let hessian = f.hessian();
assert_eq!(hessian, vec![vec![f2d!("6x"), f2d!("0")],
                         vec![f2d!("0"), f2d!("2")]]);
Source§

impl F2D

Source

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

Evaluates function at (x,y)

Source§

impl F2D

Source

pub fn set_par(&mut self, name: &str, val: f64)

Set param value by name

use ruut_functions::{f2d, F2D};

let mut f = f2d!("x+y[a]^2"); // Default value of param in 0
f.set_par("a", 6.9);
assert!(f.eval(4.20, 1.0) - 51.81 < 0.0001);
f.set_par("a", 1.2);
assert!(f.eval(4.20, 1.0) - 5.64 < 0.0001);
Source§

impl F2D

Source

pub fn new(input: &str) -> Result<Self, ParsingError>

Creates a new function from a str

Source

pub fn latex(&self) -> String

Returns a string in latex format

Trait Implementations§

Source§

impl Add<F1D> for F2D

Source§

type Output = F2D

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<F2D> for F3D

Source§

type Output = F3D

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl AddAssign<F1D> for F2D

Source§

fn add_assign(&mut self, rhs: F1D)

Performs the += operation. Read more
Source§

impl AddAssign<F2D> for F3D

Source§

fn add_assign(&mut self, rhs: F2D)

Performs the += operation. Read more
Source§

impl Debug for F2D

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for F2D

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div<F1D> for F2D

Source§

type Output = F2D

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl Div<F2D> for F3D

Source§

type Output = F3D

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl DivAssign<F1D> for F2D

Source§

fn div_assign(&mut self, rhs: F1D)

Performs the /= operation. Read more
Source§

impl DivAssign<F2D> for F3D

Source§

fn div_assign(&mut self, rhs: F2D)

Performs the /= operation. Read more
Source§

impl From<F1D> for F2D

Source§

fn from(value: F1D) -> Self

Converts to this type from the input type.
Source§

impl From<F2D> for F3D

Source§

fn from(value: F2D) -> Self

Converts to this type from the input type.
Source§

impl Mul<F1D> for F2D

Source§

type Output = F2D

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<F2D> for F3D

Source§

type Output = F3D

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl MulAssign<F1D> for F2D

Source§

fn mul_assign(&mut self, rhs: F1D)

Performs the *= operation. Read more
Source§

impl MulAssign<F2D> for F3D

Source§

fn mul_assign(&mut self, rhs: F2D)

Performs the *= operation. Read more
Source§

impl PartialEq for F2D

Source§

fn eq(&self, other: &F2D) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub<F1D> for F2D

Source§

type Output = F2D

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<F2D> for F3D

Source§

type Output = F3D

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl SubAssign<F1D> for F2D

Source§

fn sub_assign(&mut self, rhs: F1D)

Performs the -= operation. Read more
Source§

impl SubAssign<F2D> for F3D

Source§

fn sub_assign(&mut self, rhs: F2D)

Performs the -= operation. Read more
Source§

impl StructuralPartialEq for F2D

Auto Trait Implementations§

§

impl Freeze for F2D

§

impl RefUnwindSafe for F2D

§

impl Send for F2D

§

impl Sync for F2D

§

impl Unpin for F2D

§

impl UnwindSafe for F2D

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.