Skip to main content

Module numerical

Module numerical 

Source
Expand description

Numerical methods: root finding, quadrature, ODE solvers, linear algebra, interpolation. All implementations are from scratch — no external crates.

Structs§

CubicSpline
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. positions and velocities are flat arrays of length 3*N. forces_fn takes 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. bounds is 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).