Expand description
Numerical methods: root finding, quadrature, ODE solvers, linear algebra, interpolation. All implementations are from scratch — no external crates.
Structs§
- Cubic
Spline - Natural cubic spline interpolant.
- Matrix
- Dense matrix stored in row-major order.
Functions§
- adams_
bashforth4 - Adams-Bashforth 4-step method. Seeds first 4 steps with RK4, then applies the multi-step formula.
- adaptive_
simpson - Adaptive Simpson’s rule with recursive subdivision.
- barycentric
- Barycentric coordinates of point p w.r.t. triangle (a, b, c). Returns (u, v, w) such that p = ua + vb + w*c.
- bilinear
- Bilinear interpolation on a unit square. tl=top-left, tr=top-right, bl=bottom-left, br=bottom-right. tx, ty in [0,1].
- bisect
- Bisection method. Requires f(a)*f(b) < 0.
Returns the root within tolerance
tol, or None if bracket invalid or no convergence. - brent
- Brent’s method — superlinear convergence without derivative. Requires f(a)*f(b) <= 0.
- cholesky
- Cholesky decomposition for symmetric positive-definite matrices. Returns lower triangular L such that A = L * L^T. Returns None if not SPD.
- determinant
- Determinant via LU decomposition.
- eigenvalues_
2x2 - Analytic eigenvalues of a 2x2 matrix.
- euler
- Forward Euler method. Returns list of state vectors at each step.
- fixed_
point - Fixed-point iteration: x_{n+1} = g(x_n).
- gauss_
legendre - Gauss-Legendre quadrature. Supports n = 1..=5 nodes (pre-computed). Maps from [-1,1] to [a,b].
- gram_
schmidt - Gram-Schmidt orthonormalization.
- illinois
- Illinois method — a regula falsi variant with superlinear convergence.
- inverse
- Matrix inverse via LU. Returns None if singular.
- lagrange_
interp - Lagrange polynomial interpolation at x.
- leapfrog
- Leapfrog (Störmer-Verlet) symplectic integrator for N-body-style systems.
positionsandvelocitiesare flat arrays of length 3*N.forces_fntakes positions and returns force vectors (acceleration). Returns steps of (positions, velocities). - lerp
- Linear interpolation between a and b.
- lu_
decompose - LU decomposition with partial pivoting. Returns (L, U, pivot) or None if singular.
- lu_
solve - Solve LUx = Pb using forward/back substitution.
- matmul
- Matrix multiplication. Panics if dimensions mismatch.
- monte_
carlo_ integrate - Multi-dimensional Monte Carlo integration.
boundsis a slice of (low, high) per dimension. Uses a simple LCG for reproducible sampling. - muller
- Muller’s method — quadratic interpolation, can find complex roots (returns real part here).
- natural_
cubic_ spline - Build a natural cubic spline through (xs, ys).
- newton_
raphson - Newton-Raphson method.
- power_
iteration - Power iteration for the dominant eigenvalue/eigenvector.
- qr_
decompose - Thin QR decomposition via Gram-Schmidt.
- rbf_
interpolate - 2D Radial Basis Function interpolation using multiquadric RBF. centers: list of (x, y) center points, values: function value at each center.
- rk4
- Classical 4th-order Runge-Kutta.
- rk45
- Dormand-Prince RK45 adaptive step integrator. Returns (time_points, state_vectors).
- romberg
- Romberg integration — Richardson extrapolation on the trapezoidal rule.
- secant
- Secant method — Newton without explicit derivative.
- simpsons
- Simpson’s 1/3 rule. n must be even; if odd, n is incremented by 1.
- simpsons38
- Simpson’s 3/8 rule. n must be a multiple of 3; adjusted upward if not.
- solve_
linear - Solve Ax = b via LU decomposition. Returns None if singular.
- svd_2x2
- Analytic 2x2 SVD: A = U * diag(sigma) * V^T.
- transpose
- Matrix transpose.
- trapezoid
- Trapezoidal rule with n sub-intervals (n must be >= 1).
- verlet
- Störmer-Verlet integrator for second-order ODE x’’ = a(x). Returns vec of (t, x, v).