53 releases

0.15.3 Dec 8, 2023
0.15.2 Jul 8, 2023
0.15.1 Jun 21, 2023
0.14.0 Oct 2, 2022
0.0.3 Nov 19, 2018

#42 in Math

Download history 1189/week @ 2023-12-31 2160/week @ 2024-01-07 1744/week @ 2024-01-14 1345/week @ 2024-01-21 988/week @ 2024-01-28 1039/week @ 2024-02-04 1658/week @ 2024-02-11 1702/week @ 2024-02-18 1923/week @ 2024-02-25 1850/week @ 2024-03-03 1385/week @ 2024-03-10 1501/week @ 2024-03-17 1173/week @ 2024-03-24 1354/week @ 2024-03-31 1185/week @ 2024-04-07 1562/week @ 2024-04-14

5,390 downloads per month
Used in 13 crates (8 directly)

MIT license

690KB
16K SLoC

Mathru

crate documentation maintenance pipeline status

Mathru is a numeric library containing algorithms for linear algebra, analysis ,statistics and optimization written in pure Rust with optional BLAS/LAPACK as backend.

Features

The following features are implemented in this create:

  • Algebra

  • Analysis

    • Integration
      • Newton-Cotes
      • Gauss-Legendre
    • Ordinary differential equation (ODE)
      • Explicit methods
        • Euler method
        • Heun's 2nd order method
        • Midpoint method
        • Ralston's 2nd order method
        • Kutta 3rd order
        • Heun's 3rd order method
        • Ralston's 3rd order method
        • Runge-Kutta 4th order
        • Runge-Kutta-Felhberg
        • Dormand-Prince
        • Cash-Karp
        • Bogacki-Shampine
        • Adams-Bashforth
      • Automatic step size control with starting step size
      • Implicit methods
        • Implicit Euler
        • Backward differentiation formula (BDF)
    • Interpolation
      • Cubic spline
  • Optimization

    • Gauss-Newton algorithm
    • Gradient descent
    • Newton method
    • Levenberg-Marquardt algorithm
    • Conjugate gradient method
  • Statistics

    • Probability distribution
      • Bernoulli
      • Beta
      • Binomial
      • Exponential
      • Gamma
      • Chi-squared
      • Normal
      • Log-Normal
      • Poisson
      • Raised cosine
      • Student-t
      • Uniform
    • Test
  • Elementary functions

    • trigonometric functions
    • hyperbolic functions
    • exponential functions
    • power functions
    • trigonometric functions
  • Special functions

    • gamma functions
      • gamma function
      • log-gamma function
      • digamma function
      • upper incomplete gamma function
      • upper incomplete regularized gamma function
      • inverse upper incomplete regularized gamma function
      • lower incomplete gamma function
      • lower regularized incomplete gamma function
      • inverse lower regularized incomplete gamma function
    • beta functions
      • beta function
      • incomplete beta function
      • incomplete regularized beta function
    • error functions
      • error function
      • complementary error function
      • inverse error function
      • inverse complementary error function
    • hypergeometric functions

Usage

Add this to your Cargo.toml for the native Rust implementation:

[dependencies.mathru]
version = "0.15"

Add the following lines to 'Cargo.toml' if the openblas library should be used:

[dependencies.mathru]
version = "0.15"
default-features = false
features = "openblas"

One of the following implementations for linear algebra can be activated as a feature:

  • native: Native Rust implementation(activated by default)
  • openblas: Optimized BLAS library
  • netlib: Collection of mathematical software, papers, and databases
  • intel-mkl: Intel Math Kernel Library
  • accelerate Make large-scale mathematical computations and image calculations, optimized for high performance and low-energy consumption.(macOS only)

Solve a system of linear equations

use mathru::{
    algebra::linear::{
        matrix::{LUDec, Solve},
        General, Vector,
    },
    matrix, vector,
};

/// Solves a system of linear equations
fn main()
{
    let a: General<f64> = matrix![6.0, 2.0, -1.0;
                                -3.0, 5.0, 3.0; 
                                -2.0, 1.0, 3.0];
                                
    let b: Vector<f64> = vector![48.0; 
                                49.0; 
                                24.0];

    // Decompose a into a lower and upper matrix
    let lu_dec: LUDec<f64> = a.dec_lu().unwrap();

    // Solve the system of linear equations with the decomposed matrix
    let _x1: Vector<f64> = lu_dec.solve(&b).unwrap();

    // Solve it directly
    let _x2: Vector<f64> = a.solve(&b).unwrap();
}

Solve ordinary differential equation with the Dormand-Prince algorithm

use mathru::{
    algebra::linear::vector::Vector,
    analysis::differential_equation::ordinary::{problem, DormandPrince54, ExplicitODE},
};

fn main()
{
    // Create an ODE instance
    let problem: problem::Euler<f64> = problem::Euler::default();

    let (x_start, x_end) = problem.time_span();

    // Create a ODE solver instance
    let h_0: f64 = 0.0001;
    let n_max: u32 = 800;
    let abs_tol: f64 = 10e-7;

    let solver: DormandPrince54<f64> = DormandPrince54::new(abs_tol, h_0, n_max);

    // Solve ODE
    let (x, y): (Vec<f64>, Vec<Vector<f64>>) = solver.solve(&problem).unwrap();
}

Further examples

For further examples, see project page

Documentation

See project page for more information and examples. The API is documented on docs.rs.

License

Licensed under

Contribution

Any contribution is welcome!

Dependencies

~0.8–24MB
~302K SLoC