1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! Solver configuration
//!
//! The solver is defined in the `RootFinder` struct.
//!
//! To create a new solver, it is required to give the 4 following:
//! - The parameters through the `SolverParameters` struct
//! - The iteratives configuration through a reference to a slice of `Iteratives`
//! - The residuals configuration through a reference to a slice of `ResidualsConfig`
//! - The initial guess to use by the solver
//!
//! # Features
//! 1. Simulation log available for debugging, check the `set_debug()` method
//! 2. Damping, check the `set_damping()` method
//!
//!
//! ## Examples
//!
//! ```
//! use newton_rootfinder as nrf;
//! use nrf::model::Model;
//! use nrf::iteratives;
//! use nrf::residuals;
//! use nrf::solver::ResolutionMethod;
//!
//! /// Equation : x**2 - 2 = 0
//! fn square2(x: &nalgebra::DVector<f64>) -> nalgebra::DVector<f64> {
//!     let mut y = x * x;
//!     y[0] -= 2.0;
//!     y
//! }
//!
//! fn main() {
//!   let problem_size = 1;
//!   let init_guess = nalgebra::DVector::from_vec(vec![1.0]);
//!   let vec_iter_params = iteratives::default_vec_iteratives_fd(problem_size);
//!   let iter_params = iteratives::Iteratives::new(&vec_iter_params);
//!   let stopping_residuals = vec![residuals::NormalizationMethod::Abs; problem_size];
//!   let update_methods = vec![residuals::NormalizationMethod::Abs; problem_size];
//!   let res_config = residuals::ResidualsConfig::new(&stopping_residuals, &update_methods);
//!   let damping = false;
//!   let mut rf = nrf::solver::default_with_guess(init_guess, &iter_params, &res_config, ResolutionMethod::NewtonRaphson, damping);
//!   let mut user_model =
//!       nrf::model::UserModelFromFunction::new(problem_size, square2);
//!
//!   rf.solve(&mut user_model).unwrap();
//!
//!   println!("{}", user_model.get_iteratives()[0]);
//!   // print 1.4142135623747443
//! }
//! ```

mod default;
mod jacobian;
mod log;
mod parameters;
mod resolution_method;
mod rootfinder;

pub use default::default_with_guess;
pub use jacobian::evaluate_jacobian_from_analytical_function;
pub use jacobian::JacobianMatrix;
pub use jacobian::{
    approximate_inv_jacobian, approximate_jacobian, compute_jacobian_from_finite_difference,
    evaluate_jacobian_from_finite_difference,
};
pub use parameters::SolverParameters;
pub use resolution_method::greenstadt_second_method_udpate_jac;
pub use resolution_method::{
    broyden_first_method_udpate_inv_jac, broyden_second_method_udpate_inv_jac,
};
pub use resolution_method::{broyden_first_method_udpate_jac, broyden_second_method_udpate_jac};
pub use resolution_method::{quasi_method_update_inv_jac, quasi_method_update_jac};
pub use resolution_method::{QuasiNewtonMethod, ResolutionMethod, UpdateQuasiNewtonMethod};
pub use rootfinder::RootFinder;