Skip to main content

MultiVariableSolver

Struct MultiVariableSolver 

Source
pub struct MultiVariableSolver { /* private fields */ }
Expand description

Implements the finite difference method for numerical differentation for multi-variable functions

Implementations§

Source§

impl MultiVariableSolver

Source

pub fn get_step_size(&self) -> f64

Returns the step size

Source

pub fn set_step_size(&mut self, step_size: f64)

Sets the step size

Source

pub fn get_method(&self) -> FiniteDifferenceMode

Returns the chosen method of differentiation Possible choices are: Forward step, backward step and central step

Source

pub fn set_method(&mut self, method: FiniteDifferenceMode)

Sets the method of differentiation Possible choices are: Forward step, backward step and central step

Source

pub fn get_step_size_multiplier(&self) -> f64

Returns the chosen step size multiplier.

Source

pub fn set_step_size_multiplier(&mut self, multiplier: f64)

Sets the chosen step size multiplier. The step size will be multiplied by this factor after every iteration This parameter only matters if you are interested in triple derivatives or higher

Source

pub fn from_parameters( step: f64, method: FiniteDifferenceMode, multiplier: f64, ) -> Self

custom constructor, choose this for tweaking parameters if computing solutions for complex equations step: the desired step size for each iteration method: the desired method of differentiation: forward step, backward step or central step multiplier: default is 10.0, this is the factor by which we multiply the step size with on each iteration. Only matters for triple derivatives or higher

Trait Implementations§

Source§

impl Clone for MultiVariableSolver

Source§

fn clone(&self) -> MultiVariableSolver

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for MultiVariableSolver

Source§

impl Default for MultiVariableSolver

Source§

fn default() -> Self

default constructor, choose this for optimal results for most generic equations

Source§

impl DerivatorMultiVariable for MultiVariableSolver

Source§

fn get<T: ComplexFloat, const NUM_VARS: usize, const NUM_ORDER: usize>( &self, order: usize, func: &dyn Fn(&[T; NUM_VARS]) -> T, idx_to_derivate: &[usize; NUM_ORDER], point: &[T; NUM_VARS], ) -> Result<T, &'static str>

Returns the numerical differentiation value for a multi variable function order: number of times the equation should be differentiated func: the multi variable function idx_to_derivate: The variable index/indices whose respect to we want to differentiate point: the point of interest around which we want to differentiate

NOTE: Returns a Result<T, &’static str> Possible &’static str are: NUMBER_OF_DERIVATIVE_STEPS_CANNOT_BE_ZERO -> if the step size value is zero DERIVATE_ORDER_CANNOT_BE_ZERO -> if the ‘order’ argument is zero INDEX_TO_DERIVATE_ILL_FORMED -> if size of ‘idx_to_derivate’ argument is not equal to the ‘order’ argument

assume we want to differentiate f(x,y,z) = ysin(x) + xcos(y) + xye^z. the function would be:

   let my_func = | args: &[f64; 3] | -> f64 
   { 
       return args[1]*args[0].sin() + args[0]*args[1].cos() + args[0]*args[1]*args[2].exp();
   };

let point = [1.0, 2.0, 3.0]; //the point at which we want to differentiate


use multicalc::numerical_derivative::derivator::*;
use multicalc::numerical_derivative::finite_difference::*;

let derivator = MultiVariableSolver::default();

let idx: [usize; 2] = [0, 1]; //mixed partial double derivate d(df/dx)/dy
let val = derivator.get(2, &my_func, &idx, &point).unwrap();
let expected_value = f64::cos(1.0) - f64::sin(2.0) + f64::exp(3.0);
assert!(f64::abs(val - expected_value) < 0.001);

let idx: [usize; 2] = [1, 1]; //partial double derivative d(df/dy)/dy 
let val = derivator.get(2, &my_func, &idx, &point).unwrap();
let expected_value = -1.0*f64::cos(2.0);
assert!(f64::abs(val - expected_value) < 0.0001);
Source§

fn get_single_partial<T: ComplexFloat, const NUM_VARS: usize>( &self, func: &dyn Fn(&[T; NUM_VARS]) -> T, idx_to_derivate: usize, point: &[T; NUM_VARS], ) -> Result<T, &'static str>

convenience wrapper for a single partial derivative of a multivariable function
Source§

fn get_double_partial<T: ComplexFloat, const NUM_VARS: usize>( &self, func: &dyn Fn(&[T; NUM_VARS]) -> T, idx_to_derivate: &[usize; 2], point: &[T; NUM_VARS], ) -> Result<T, &'static str>

convenience wrapper for a double partial derivative of a multivariable function

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.