| Crates.io | convex-math |
| lib.rs | convex-math |
| version | 0.11.1 |
| created_at | 2025-12-07 13:02:58.670461+00 |
| updated_at | 2026-01-07 07:02:09.398111+00 |
| description | Mathematical utilities for the Convex fixed income analytics library |
| homepage | |
| repository | https://github.com/sujitn/convex |
| max_upload_size | |
| id | 1971547 |
| size | 214,241 |
Mathematical utilities for the Convex fixed income analytics library.
convex-math provides numerical algorithms commonly used in fixed income calculations:
use convex_math::solvers::{newton_raphson, brent, bisection, SolverConfig};
// Newton-Raphson (requires derivative)
let f = |x: f64| x * x - 2.0;
let df = |x: f64| 2.0 * x;
let result = newton_raphson(f, df, 1.5, &SolverConfig::default()).unwrap();
// result.root ≈ √2
// Brent's method (bracketing, no derivative needed)
let result = brent(f, 1.0, 2.0, &SolverConfig::default()).unwrap();
// Bisection (simple but reliable)
let result = bisection(f, 1.0, 2.0, &SolverConfig::default()).unwrap();
use convex_math::interpolation::{LinearInterpolator, CubicSpline, Interpolator};
// Linear interpolation
let xs = vec![0.0, 1.0, 2.0, 3.0];
let ys = vec![0.0, 1.0, 4.0, 9.0];
let linear = LinearInterpolator::new(xs.clone(), ys.clone()).unwrap();
let y = linear.interpolate(1.5).unwrap();
// Cubic spline (smoother)
let spline = CubicSpline::new(xs, ys).unwrap();
let y = spline.interpolate(1.5).unwrap();
use convex_math::linear_algebra::{solve_tridiagonal, solve_linear_system};
use nalgebra::{DMatrix, DVector};
// Efficient tridiagonal solver (common in spline fitting)
let a = vec![1.0, 1.0]; // Lower diagonal
let b = vec![2.0, 2.0, 2.0]; // Main diagonal
let c = vec![1.0, 1.0]; // Upper diagonal
let d = vec![1.0, 2.0, 3.0]; // RHS
let x = solve_tridiagonal(&a, &b, &c, &d).unwrap();
// General linear system
let a = DMatrix::from_row_slice(2, 2, &[2.0, 1.0, 1.0, 3.0]);
let b = DVector::from_vec(vec![5.0, 5.0]);
let x = solve_linear_system(&a, &b).unwrap();
Add to your Cargo.toml:
[dependencies]
convex-math = "0.1"
This project is licensed under the MIT License - see the LICENSE file for details.