Skip to content

Commit

Permalink
fix all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kmolan committed Jun 30, 2024
1 parent 57441c2 commit 3dd3668
Show file tree
Hide file tree
Showing 18 changed files with 417 additions and 1,536 deletions.
9 changes: 5 additions & 4 deletions src/approximation/linear_approximation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<D: DerivatorMultiVariable> LinearApproximator<D>
{
pub fn from_derivator(derivator: D) -> Self
{
return LinearApproximator {derivator: derivator}
return LinearApproximator {derivator}
}

/// For an n-dimensional approximation, the equation is linearized as:
Expand All @@ -108,16 +108,17 @@ impl<D: DerivatorMultiVariable> LinearApproximator<D>
///
///example function is x + y^2 + z^3, which we want to linearize. First define the function:
///```
///use multicalc::approximation::linear_approximation;
///use multicalc::approximation::linear_approximation::*;
///use multicalc::numerical_derivative::finite_difference::MultiVariableSolver;
///
///let function_to_approximate = | args: &[f64; 3] | -> f64
///{
/// return args[0] + args[1].powf(2.0) + args[2].powf(3.0);
///};
///
///let point = [1.0, 2.0, 3.0]; //the point we want to linearize around
///
///let result = linear_approximation::get(&function_to_approximate, &point);
///let approximator = LinearApproximator::<MultiVariableSolver>::default();
///let result = approximator.get(&function_to_approximate, &point).unwrap();
///
///assert!(f64::abs(function_to_approximate(&point) - result.get_prediction_value(&point)) < 1e-9);
/// ```
Expand Down
10 changes: 6 additions & 4 deletions src/approximation/quadratic_approximation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<D: DerivatorMultiVariable> QuadraticApproximator<D>
{
pub fn from_derivator(derivator: D) -> Self
{
return QuadraticApproximator {derivator: derivator};
return QuadraticApproximator {derivator};
}

/// For an n-dimensional approximation, the equation is approximated as I + L + Q, where:
Expand All @@ -120,16 +120,18 @@ impl<D: DerivatorMultiVariable> QuadraticApproximator<D>
///
///example function is e^(x/2) + sin(y) + 2.0*z, which we want to approximate. First define the function:
///```
///use multicalc::approximation::quadratic_approximation;
///use multicalc::approximation::quadratic_approximation::*;
///use multicalc::numerical_derivative::finite_difference::MultiVariableSolver;
///
///let function_to_approximate = | args: &[f64; 3] | -> f64
///{
/// return f64::exp(args[0]/2.0) + f64::sin(args[1]) + 2.0*args[2];
///};
///
///let point = [0.0, 1.57, 10.0]; //the point we want to approximate around
///
///let result = quadratic_approximation::get(&function_to_approximate, &point);
///
///let approximator = QuadraticApproximator::<MultiVariableSolver>::default();
///let result = approximator.get(&function_to_approximate, &point).unwrap();
///
///assert!(f64::abs(function_to_approximate(&point) - result.get_prediction_value(&point)) < 1e-9);
/// ```
Expand Down
4 changes: 4 additions & 0 deletions src/numerical_derivative/derivator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use num_complex::ComplexFloat;


///Base trait for single variable numerical differentiation
pub trait DerivatorSingleVariable: Default + Clone + Copy
{
///generic n-th derivative of a single variable function
Expand All @@ -18,6 +20,8 @@ pub trait DerivatorSingleVariable: Default + Clone + Copy
}
}


///Base trait for multi-variable numerical differentiation
pub trait DerivatorMultiVariable: Default + Clone + Copy
{
///generic n-th derivative for a multivariable function of a multivariable function
Expand Down
191 changes: 0 additions & 191 deletions src/numerical_derivative/double_derivative.rs

This file was deleted.

Loading

0 comments on commit 3dd3668

Please sign in to comment.