eqsolver - An Equation Solving, Optimisation, and Integration Library for Rust
This Rust library is aimed at numerically solving equations, optimising objective functions, and integrating functions.
The library is passively-maintained, meaning no other features will be added. However, issues on the GitHub will be answered and solved.
Contributions and feedback to this library are more than welcome!
Supported Methods
The following methods are available to use in the library. Their descriptions use the largest possible domain and codomain for the functions, which is Rn. However, any (well-behaved) subset of Rn also works. Additionally, the methods that use multivariate input or output heavily utilises the linear algebra library for Rust nalgebra.
Single Variable
Multivariate
There are two versions of this method, one requires the Jacobian matrix to be given and the other approximates it using finite differences. The latter version has, therefore, slightly longer wall time. Both methods require an initial guess.
For certain ill-posed problems, this method will fail. For a slower but more robust method, see the Levenberg-Marquardt method below.
There are two versions of this method, one requires the Jacobian matrix to be given and the other approximates it using finite differences. The latter version has, therefore, slightly longer wall time. Both methods require an initial guess.
For certain ill-posed problems, this method will fail. For a slower but more robust method, see the Levenberg-Marquardt method below.
There are two versions of this method, one requires the Jacobian matrix to be given and the other approximates it using finite differences. The latter version has, therefore, slightly longer wall time. Both methods require an initial guess.
Global Optimisers of Objective Functions
Use this method if you know the bounds of the parameters.
Use this method if you DON'T KNOW the bounds of the parameters but KNOW how uncertain each parameter is.
Ordinary Differential Equations (or systems of them)
There is a single struct for ordinary differential equations (ODE) which can be modified (using
the builder pattern) to use one of the following step methods:
Numerical Integrators
In eqsolver, there are structs that represents methods for integrating functions f: Rn → R.
Note! This method cannot guarantee a tolerance. Use Adaptive Newton-Cotes for a guarantee on error.
The integrator may be inputted with a random number generator (RNG), seeded (ChaCha8, for instance) or non-seeded (rand's RNG).
Furthermore, the output of the integrator is the mean and variance of algorithm's output where the former is the integral's value.
The struct uses parameters inspired by GNU's Scientific Library (GSL)'s implementation. These include a dither value to break symmetries of functions, an alpha value (introduced by Press and Farrar) to control the variance-based distribution of points, and parameters regarding the bounds on recursion and sample count.
Like the plain Monte Carlo integrator, MISER may be inputted with an RNG, and the output is a mean with a variance.
Examples
Example of Newton-Raphson's method with finite differences.
use FDNewton;
let f = ; // e^x = 1/x
let solution = new.solve; // Starting guess is 0.5
Example of Newton-Raphson's method with finite differences for system of equations
use MultiVarNewtonFD;
use ;
// Want to solve x^2 - y = 1 and xy = 2
let f = ;
let solution = new.solve; // Starting guess is (1, 1)
Example of solution for a single first order ODEs
use ODESolver;
let f = ; // y' = f(t, y) = ty
let = ;
let x_end = 2.;
let step_size = 1e-3;
let solution = new.solve;
Example of solving a non-linear least square problem with the Levenberg-Marquardt method
use LevenbergMarquardtFD;
use ;
let c0 = ;
let c1 = ;
let c2 = ;
// Function from R2 to R3
let f = ;
let solution_lm = new
.solve // Guess
.unwrap;
Example of using global optimisers on the Rastrigin function
use ;
use SVector;
use PI;
const SIZE: usize = 10;
let rastrigin = ;
let bounds = repeat;
let standard_deviations = repeat;
let guess = repeat;
let opt_pso = new.solve;
let opt_ce = new
.with_std_dev
.solve;
Example of Newton-Cotes integration
use AdaptiveNewtonCotes;
Example of MISER integration
use ;
use ;
use SeedableRng;
use ChaCha8Rng;
For more examples, please see the examples directory.