Peroxide

On crates.io On docs.rs travis
maintenance

Pure Rust numeric library contains linear algebra, numerical analysis, statistics and machine learning tools with R, MATLAB, Python like macros.

Latest README version

Corresponding to 0.8.7.

Install

Module Structure

Documentation

There is Peroxide Gitbook

Not yet documentized contents

Polynomial

```rust // Peroxide extern crate peroxide; use peroxide::*;

fn main() { // Declare polynomial let a = poly(c!(1,3,2)); a.print(); // x^2 + 3x + 2 a.eval(1); // Evaluate when x = 1 -> 6.0

let b = poly(c!(1,2,3,4));       // x^3 + 2x^2 + 3x + 4
(a.clone() + b.clone()).print(); // x^3 + 3x^2 + 6x + 6
(a.clone() - b.clone()).print(); // -x^3 - x^2 - 2
(a.clone() * b.clone()).print(); // x^5 + 5x^4 + 11x^3 + 17x^2 + 18x + 8

let c = poly(c!(1, -1));
c.print();                       // x - 1
c.pow(2).print();                // x^2 - 2x + 1

} ```

Interpolation (Beta)

```rust // Peroxide extern crate peroxide; use peroxide::*;

fn main() { let a = c!(-1, 0, 1); let b = c!(1, 0, 1);

let l = lagrange_polynomial(a, b);
l.print(); // x^2

} ```

Spline (Beta)

```rust // Peroxide extern crate peroxide; use peroxide::*;

fn main() { let x = c!(0.9, 1.3, 1.9, 2.1); let y = c!(1.3, 1.5, 1.85, 2.1);

let s = cubic_spline(x, y);

for i in 0 .. s.len() {
    s[i].print();
}

// -0.2347x^3 + 0.6338x^2 - 0.0329x + 0.9873
// 0.9096x^3 - 3.8292x^2 + 5.7691x - 1.5268
// -2.2594x^3 + 14.2342x^2 - 28.5513x + 20.2094

} ```

MATLAB like macro

Automatic Differentiation

```rust extern crate peroxide; use peroxide::*;

fn main() { let a = dual(0, 1); // x at x = 0 a.sin().print(); // sin(x) at x = 0

// value: 0  // sin(0) = 0
// slope: 1  // cos(0) = 1

} ```

Jacobian

```rust extern crate peroxide; use peroxide::*;

fn main() { let xs = c!(1, 1); jacobian(xs, f).print();

//      c[0] c[1]
// r[0]    6    3

}

// f(t, x) = 3t^2 * x fn f(xs: Vec) -> Vec { let t = xs[0]; let x = xs[1];

vec![t.pow(2) * 3. * x]

} ```

Ordinary Differential Equation

Caution

```rust // Lotka-Volterra extern crate peroxide; use peroxide::*;

fn main() { // t = 0, x = 2, y = 1 let xs = c!(2, 1); let rk4records = solve(lotkavolterra, xs.clone(), (0, 10), 1e-3, RK4); let bdfrecords = solve(lotkavolterra, xs.clone(), (0, 10), 1e-3, BDF1(1e-15)); let gl4records = solve(lotkavolterra, xs, (0, 10), 1e-3, GL4(1e-15)); //rk4records.writewithheader("exampledata/lotkark4.csv", vec!["t", "x", "y"]); //bdfrecords.writewithheader("exampledata/lotkabdf.csv", vec!["t", "x", "y"]); gl4records.writewithheader("exampledata/lotka_gl4.csv", vec!["t", "x", "y"]); }

fn lotkavolterra(t: Dual, xs: Vec) -> Vec { let a = 4.; let c = 1.;

let x = xs[0];
let y = xs[1];

vec![
    a * (x - x*y),
    -c * (y - x*y)
]

} ```

Version Info

To see RELEASES.md

TODO

To see TODO.md