Pure Rust numeric library contains linear algebra, numerical analysis, statistics and machine learning tools with R, MATLAB, Python like macros.
Corresponding to 0.8.7
.
cargo.toml
toml
peroxide = "0.8"
mod
and re-export
rand
crateVec<f64>
There is Peroxide Gitbook
```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
} ```
```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
} ```
```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
} ```
zeros
- zero vector or matrixeye
- identity matrixrand
- random matrix (range from 0 to 1)sin, cos, tan
pow, powf
+,-,x,/
exp, ln
```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
} ```
```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![t.pow(2) * 3. * x]
} ```
RK4
: Runge-Kutta 4th orderBDF1
: Backward EulerGL4
: Gauss-Legendre 4th orderCaution
(Dual, Vec<Dual>) -> Vec<Dual>
```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
let x = xs[0];
let y = xs[1];
vec![
a * (x - x*y),
-c * (y - x*y)
]
} ```
To see RELEASES.md
To see TODO.md