pub struct MultiVariableSolver { /* private fields */ }Expand description
Implements the finite difference method for numerical differentation for multi-variable functions
Implementations§
Source§impl MultiVariableSolver
impl MultiVariableSolver
Sourcepub fn get_step_size(&self) -> f64
pub fn get_step_size(&self) -> f64
Returns the step size
Sourcepub fn set_step_size(&mut self, step_size: f64)
pub fn set_step_size(&mut self, step_size: f64)
Sets the step size
Sourcepub fn get_method(&self) -> FiniteDifferenceMode
pub fn get_method(&self) -> FiniteDifferenceMode
Returns the chosen method of differentiation Possible choices are: Forward step, backward step and central step
Sourcepub fn set_method(&mut self, method: FiniteDifferenceMode)
pub fn set_method(&mut self, method: FiniteDifferenceMode)
Sets the method of differentiation Possible choices are: Forward step, backward step and central step
Sourcepub fn get_step_size_multiplier(&self) -> f64
pub fn get_step_size_multiplier(&self) -> f64
Returns the chosen step size multiplier.
Sourcepub fn set_step_size_multiplier(&mut self, multiplier: f64)
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
Sourcepub fn from_parameters(
step: f64,
method: FiniteDifferenceMode,
multiplier: f64,
) -> Self
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
impl Clone for MultiVariableSolver
Source§fn clone(&self) -> MultiVariableSolver
fn clone(&self) -> MultiVariableSolver
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for MultiVariableSolver
Source§impl Default for MultiVariableSolver
impl Default for MultiVariableSolver
Source§impl DerivatorMultiVariable for MultiVariableSolver
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>
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);