/** * Typed Numerical Methods Functions * * Root finding, optimization, integration, interpolation, curve fitting, * ODE solvers, and linear algebra utilities. All implementations are * pure TypeScript with the WASM acceleration path pattern. * * These use plain exports (not mathTyped) because most accept function * arguments, which typed-function does not handle well. * * @packageDocumentation */ export { solveParabolicPDE, type SolveParabolicPDEOptions, type ParabolicPDESolution, type ParabolicBC, type SpaceCoefficient, type BoundaryDatum, type ParabolicSource, } from '../numeric/solveParabolicPDE.js'; export { solveDAE, type SolveDAEOptions, type DAESolution, type DAEDifferential, type DAEConstraint, type DAEJacobianBlocks, } from '../numeric/solveDAE.js'; export { solveDDE, type SolveDDEOptions, type DDESolution, type DDEForcing, type DDEHistory, } from '../numeric/solveDDE.js'; type f64 = number; type i32 = number; /** * Options for root-finding algorithms. */ export interface FindRootOptions { /** Absolute tolerance for convergence (default 1e-12) */ tol?: f64; /** Maximum iterations (default 100) */ maxIter?: i32; } /** * Find a root of f(x) = 0 in [a, b] using Brent's method. * * Brent's method combines bisection, secant, and inverse quadratic * interpolation for superlinear convergence with guaranteed reliability. * * @param f - Continuous function * @param a - Lower bound (f(a) and f(b) must have opposite signs) * @param b - Upper bound * @param opts - Options (tol, maxIter) * @returns Approximate root * * @example * findRoot(x => x**2 - 2, 1, 2) // => ~1.4142135 */ export declare function findRoot(f: (x: f64) => f64, a: f64, b: f64, opts?: FindRootOptions): f64; /** * Solve linear system Ax = b using LU decomposition with partial pivoting. * * @param A - Coefficient matrix (n x n) * @param b - Right-hand side vector (length n) * @returns Solution vector x * * @example * linsolve([[2, 1], [1, 3]], [5, 10]) // => [1, 3] */ export declare function linsolve(A: number[][], b: number[]): number[]; /** * Options for optimization algorithms. */ export interface MinimizeOptions { /** Absolute tolerance (default 1e-8) */ tol?: f64; /** Maximum iterations (default 1000) */ maxIter?: i32; /** Initial simplex step size (default 0.1) */ step?: f64; } /** * Minimize a function using the Nelder-Mead simplex method. * * @param f - Objective function (n-dimensional input) * @param x0 - Initial guess * @param opts - Options * @returns Approximate minimizer * * @example * minimize(x => (x[0]-1)**2 + (x[1]-2)**2, [0, 0]) // => ~[1, 2] */ export declare function minimize(f: (x: number[]) => f64, x0: number[], opts?: MinimizeOptions): number[]; /** * Maximize a function using Nelder-Mead (negates objective). * * @param f - Objective function * @param x0 - Initial guess * @param opts - Options * @returns Approximate maximizer */ export declare function maximize(f: (x: number[]) => f64, x0: number[], opts?: MinimizeOptions): number[]; /** * Global minimization using basin-hopping (random perturbation + local min). * * @param f - Objective function * @param bounds - Array of [min, max] for each dimension * @param opts - Options (maxIter controls number of hops) * @returns Approximate global minimizer */ export declare function globalMinimize(f: (x: number[]) => f64, bounds: [number, number][], opts?: MinimizeOptions & { nHops?: i32; }): number[]; /** * Least squares solution: minimize ||Ax - b||^2 via normal equations. * * @param A - Matrix (m x n), m >= n * @param b - Right-hand side (length m) * @returns Least squares solution x (length n) */ export declare function leastSquares(A: number[][], b: number[]): number[]; /** * Adaptive numerical integration via Gauss-Kronrod (G7-K15) quadrature (see * {@link quad} in `../numeric/adaptive-quad.js`). Previously used a fixed * 5-point Gauss-Legendre panel with Richardson-extrapolation adaptivity, * which converged slowly on endpoint singularities (e.g. `x^-1/2` near 0, * ~1.7e-6 error); G7-K15's embedded error estimate resolves those panels * directly, down to ~1e-10. * * @param f - Function to integrate * @param a - Lower bound * @param b - Upper bound * @param opts - Options (tol, maxDepth for max subdivisions) * @returns Approximate integral */ export declare function nintegrate(f: (x: f64) => f64, a: f64, b: f64, opts?: { tol?: f64; maxDepth?: i32; }): f64; /** * Simpson's 1/3 rule (convenience alias). * * @param f - Function to integrate * @param a - Lower bound * @param b - Upper bound * @param n - Number of subintervals (even, default 100) * @returns Approximate integral */ export declare function simpsons(f: (x: f64) => f64, a: f64, b: f64, n?: i32): f64; /** * Unified interpolation API. * * @param xs - Sorted x-coordinates * @param ys - Corresponding y-values * @param method - 'linear' | 'lagrange' | 'spline' (default 'linear') * @returns Interpolation function */ export declare function interpolate(xs: number[], ys: number[], method?: 'linear' | 'lagrange' | 'spline'): (x: f64) => f64; /** * Cubic spline interpolation (alias). */ export declare function cspline(xs: number[], ys: number[]): (x: f64) => f64; /** * PCHIP interpolation (alias wrapping the value-returning function). */ export declare function pchip(xs: number[], ys: number[], x: f64): f64; /** * Evaluate a Bezier curve at parameter t. * * @param controlPoints - Array of control points (each a number[]) * @param t - Parameter in [0, 1] * @returns Point on curve */ export declare function bezierCurve(controlPoints: number[][], t: f64): number[]; /** * Evaluate a B-spline at parameter t. * * @param controlPoints - Array of control points * @param degree - Spline degree (must be < number of control points) * @param t - Parameter in [0, 1] * @returns Point on B-spline */ export declare function bspline(controlPoints: number[][], degree: i32, t: f64): number[]; /** * LOESS/LOWESS locally weighted regression. * * @param xs - x-coordinates * @param ys - y-values * @param x - Point to evaluate * @param bandwidth - Fraction of data to use (default 0.3) * @returns Smoothed value at x */ export declare function loess(xs: number[], ys: number[], x: f64, bandwidth?: f64): f64; /** * Scattered data gridding using inverse distance weighting. * * @param points - Array of [x, y] data locations * @param values - Corresponding values * @param xi - x-coordinates of grid * @param yi - y-coordinates of grid * @returns 2D array of interpolated values [yi.length][xi.length] */ export declare function griddata(points: number[][], values: number[], xi: number[], yi: number[]): number[][]; /** * Radial basis function interpolation. * * @param points - Data point locations (array of number[]) * @param values - Data values * @param xi - Query points * @param kernel - RBF kernel: 'gaussian' | 'multiquadric' | 'thinplate' (default 'gaussian') * @returns Interpolated values at xi */ export declare function rbfInterpolate(points: number[][], values: number[], xi: number[][], kernel?: 'gaussian' | 'multiquadric' | 'thinplate'): number[]; /** * Nonlinear curve fitting using Levenberg-Marquardt algorithm. * * @param f - Model function f(x, params) => y * @param xs - x data * @param ys - y data * @param p0 - Initial parameter guess * @returns Fitted parameters */ export declare function curvefit(f: (x: f64, params: number[]) => f64, xs: number[], ys: number[], p0: number[]): number[]; /** * Exponential fit: y = a * exp(b * x). * * @param xs - x data * @param ys - y data (must be positive) * @returns [a, b] coefficients */ export declare function expfit(xs: number[], ys: number[]): [f64, f64]; /** * Logarithmic fit: y = a * ln(x) + b. * * @param xs - x data (must be positive) * @param ys - y data * @returns [a, b] coefficients */ export declare function logfit(xs: number[], ys: number[]): [f64, f64]; /** * Power fit: y = a * x^b. * * @param xs - x data (must be positive) * @param ys - y data (must be positive) * @returns [a, b] coefficients */ export declare function powerfit(xs: number[], ys: number[]): [f64, f64]; /** * ODE solution result. */ export interface ODESolution { t: number[]; y: number[][]; } /** * Solve a system of ODEs dy/dt = f(t, y). * * By default (no `dt`) it uses **adaptive** embedded RK45 (Dormand-Prince) with local-error control * — the step size is chosen automatically to keep the scaled RMS error under `tol`. Passing an * explicit `dt` selects the legacy **fixed-step** RK4 integrator instead (unchanged, for callers * that want a prescribed step, e.g. the BVP shooting driver). * * @param f - System function (t, y) => dy/dt * @param y0 - Initial state vector * @param tspan - [t0, tf] time span * @param opts - Options: `tol` (adaptive local-error tolerance, default 1e-6), `maxSteps` (step * cap), `dt` (fixed step — selects the legacy fixed-step RK4 path) * @returns Solution { t, y } */ export declare function solveODESystem(f: (t: f64, y: number[]) => number[], y0: number[], tspan: [f64, f64], opts?: { tol?: f64; maxSteps?: i32; dt?: f64; }): ODESolution; /** * Solve stiff ODE systems. * * Delegates to the shared L-stable Rosenbrock (ode23s) engine (`rosenbrockSolve`, * `functions/src/numeric/solveODE.ts` — the same engine `solveODE(..., {method:'Rosenbrock'})` * uses). The previous implementation was fixed-step implicit Euler solved by fixed-point * iteration, which cannot converge when `h·|∂f/∂y|` is large — exactly the stiff regime this * function targets (71% error on `y'=-15y`; `null`/NaN on the stiff mode of `diag(-1,-1000)`). * * @param f - System function * @param y0 - Initial state * @param tspan - Time span * @returns Solution */ export declare function stiffODESolver(f: (t: f64, y: number[]) => number[], y0: number[], tspan: [f64, f64]): ODESolution; /** * Solve a boundary value problem for a general first-order system * `y' = f(t, y)` with two-point boundary condition `bc(y(t0), y(tf)) = 0`, * via single shooting + Newton iteration on the initial state. * * The unknowns are the full initial state `y(t0)` (length `n`); Newton's * method adjusts them until `bc` (the boundary residual, length `n`) is * driven to zero, using a forward-difference numerical Jacobian of `shoot` * (re-integrating the IVP per Jacobian column) and `linsolve` for the * Newton step. `n` defaults to 2 (the original * hardcoded case — a single 2nd-order ODE cast as the 2-state system * `[y, y']`, the most common BVP shape) but generalizes to any state * dimension via `y0Guess`, whose length becomes `n`. This makes `solveBVP` * applicable to any first-order system, not just 2-state ones — pass an * `n`-length initial guess for higher-order/coupled systems. * * @param f - System function (t, y) => dy/dt * @param bc - Boundary condition function (y0, yf) => residuals (length n) * @param mesh - Initial mesh points (only the endpoints are used — [mesh[0], mesh[last]]) * @param y0Guess - Initial guess for the shooting unknowns y(t0); its length sets * the state dimension n. Defaults to `[0, 0]` (back-compat 2-state case). * @returns Solution */ export declare function solveBVP(f: (t: f64, y: number[]) => number[], bc: (y0: number[], yf: number[]) => number[], mesh: number[], y0Guess?: number[]): ODESolution; /** * Single adaptive RK step returning (y_new, error_estimate). * * @param f - System function * @param y0 - Current state * @param t0 - Current time * @param h - Step size * @param tol - Error tolerance * @returns `{ y: number[], t: number, h: number }` with updated step size */ export declare function odeAdaptiveStep(f: (t: f64, y: number[]) => number[], y0: number[], t0: f64, h: f64, tol?: f64): { y: number[]; t: f64; h: f64; }; /** * ODE integration with event detection. * Stops when event(t, y) crosses zero. * * @param f - System function * @param y0 - Initial state * @param tspan - Time span * @param event - Event function; integration stops when this crosses zero * @returns Solution up to event */ export declare function eventDetection(f: (t: f64, y: number[]) => number[], y0: number[], tspan: [f64, f64], event: (t: f64, y: number[]) => f64): ODESolution & { eventTime?: f64; }; /** * Numerical rank of a matrix using SVD-like approach. * * @param A - Matrix (m x n) * @param tol - Tolerance for zero singular values (default 1e-10) * @returns Numerical rank */ export declare function rank(A: number[][], tol?: f64): i32; /** * Null space basis of a matrix. * * @param A - Matrix (m x n) * @returns Array of basis vectors spanning the null space */ export declare function nullspace(A: number[][]): number[][]; /** * Partial fraction decomposition residues for P(x)/Q(x). * Assumes Q has distinct real roots. Returns residues at roots. * * @param p - Numerator polynomial coefficients [a0, a1, ..., an] for a0 + a1*x + ... * @param q - Denominator polynomial coefficients * @returns `{ residues: number[], poles: number[] }` */ export declare function residue(p: number[], q: number[]): { residues: number[]; poles: number[]; }; /** * Chebyshev polynomial approximation of a function on [a, b]. * * @param f - Function to approximate * @param a - Lower bound * @param b - Upper bound * @param n - Number of terms (default 10) * @returns Evaluation function */ export declare function chebyshevApprox(f: (x: f64) => f64, a: f64, b: f64, n?: i32): (x: f64) => f64; /** * Pade approximant [m/n] from Taylor coefficients. * * @param coeffs - Taylor series coefficients [c0, c1, c2, ...] * @param m - Numerator degree * @param n - Denominator degree * @returns `{ num: number[], den: number[] }` polynomial coefficients */ export declare function padeApproximant(coeffs: number[], m: i32, n: i32): { num: number[]; den: number[]; }; /** * Quadratic programming: minimize 0.5 * x^T H x + f^T x subject to A x <= b. * Uses projected gradient descent. * * @param H - Hessian matrix (n x n, positive definite) * @param f - Linear term (length n) * @param A - Inequality constraint matrix (m x n) * @param b - Inequality constraint bounds (length m) * @returns Solution vector x */ export declare function quadprog(H: number[][], f: number[], A: number[][], b: number[]): number[]; /** * Options form of {@link linprog}: minimize c^T x subject to A_ub x <= b_ub, * A_eq x = b_eq, and per-variable bounds. */ export interface LinprogOptions { A_ub?: number[][]; b_ub?: number[]; A_eq?: number[][]; b_eq?: number[]; /** Per-variable [lower, upper] bounds; null = unbounded. Default: [0, null] for every variable. */ bounds?: readonly (readonly [number | null, number | null])[]; } /** Result of the options form of {@link linprog}. */ export interface LinprogResult { x: number[]; fun: number; success: boolean; status: 'optimal' | 'infeasible' | 'unbounded'; } /** * Linear programming: minimize c^T x. * * Two overloads: * - Legacy positional form `linprog(c, A_ub, b_ub)` — subject to `A_ub x <= b_ub`, * `x >= 0`; returns the solution vector `x` (or `null` if unbounded). * - Options form `linprog(c, { A_ub, b_ub, A_eq, b_eq, bounds })` — a two-phase * simplex supporting equality constraints, variable bounds, and negative-RHS * rows; returns `{ x, fun, success, status }`. */ export declare function linprog(c: number[], A_ub: number[][], b_ub: number[]): number[] | null; export declare function linprog(c: number[], opts: LinprogOptions): LinprogResult; /** * Simple 1D PDE solver using finite differences (heat equation). * * Solves u_t = alpha * u_xx on domain [0, L] with boundary conditions. * * @param pde - { alpha: diffusion coefficient } * @param domain - { L: domain length, nx: spatial points, nt: time steps, T: final time } * @param bc - { left: left BC value, right: right BC value, initial: initial condition function } * @returns `{ x: number[], u: number[] }` solution at final time */ export declare function solvePDE(pde: { alpha: f64; }, domain: { L: f64; nx: i32; nt: i32; T: f64; }, bc: { left: f64; right: f64; initial: (x: f64) => f64; }): { x: number[]; u: number[]; }; //# sourceMappingURL=numeric.d.ts.map