@danielsimonjr/mathts-functions 0.28.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +926 -101
- package/dist/linalg-svd-extra.d.ts +21 -0
- package/dist/linalg-svd-extra.d.ts.map +1 -0
- package/dist/numeric/adaptive-quad.d.ts +56 -0
- package/dist/numeric/adaptive-quad.d.ts.map +1 -0
- package/dist/numeric/bfgs.d.ts +70 -0
- package/dist/numeric/bfgs.d.ts.map +1 -0
- package/dist/numeric/fsolve.d.ts +45 -0
- package/dist/numeric/fsolve.d.ts.map +1 -0
- package/dist/numeric/minimize-scalar.d.ts +56 -0
- package/dist/numeric/minimize-scalar.d.ts.map +1 -0
- package/dist/numeric/nnls.d.ts +72 -0
- package/dist/numeric/nnls.d.ts.map +1 -0
- package/dist/numeric/numeric-jacobian.d.ts +28 -0
- package/dist/numeric/numeric-jacobian.d.ts.map +1 -0
- package/dist/numeric/open-root-finders.d.ts +95 -0
- package/dist/numeric/open-root-finders.d.ts.map +1 -0
- package/dist/typed/cas.d.ts +13 -4
- package/dist/typed/cas.d.ts.map +1 -1
- package/dist/typed/numeric.d.ts +35 -10
- package/dist/typed/numeric.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Options for {@link orth}. */
|
|
2
|
+
export interface OrthOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Rank-determination tolerance. Singular values `> tol` count toward the
|
|
5
|
+
* rank. Default: `max(m, n) * S[0] * 2.22e-16` (machine epsilon scaled by
|
|
6
|
+
* matrix size and the largest singular value).
|
|
7
|
+
*/
|
|
8
|
+
tol?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Orthonormal basis for the column space of `A`.
|
|
12
|
+
*
|
|
13
|
+
* Computes `{ U, S } = svd(A)` and returns the first `r` columns of `U`,
|
|
14
|
+
* where `r` is the number of singular values above `tol`. For the all-zero
|
|
15
|
+
* matrix (`r = 0`), returns an `m x 0` matrix (each row an empty array).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* orth([[1,0,1],[0,1,1],[1,1,2]]) // rank 2 -> 3x2 matrix, U^T U = I
|
|
19
|
+
*/
|
|
20
|
+
export declare function orth(A: number[][], opts?: OrthOptions): number[][];
|
|
21
|
+
//# sourceMappingURL=linalg-svd-extra.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linalg-svd-extra.d.ts","sourceRoot":"","sources":["../src/linalg-svd-extra.ts"],"names":[],"mappings":"AAWA,gCAAgC;AAChC,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,GAAE,WAAgB,GAAG,MAAM,EAAE,EAAE,CAQtE"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adaptive Gauss-Kronrod (G7-K15) quadrature.
|
|
3
|
+
*
|
|
4
|
+
* QUADPACK-style adaptive numerical integration: on each subinterval, a
|
|
5
|
+
* 15-point Kronrod estimate `K` is compared against the embedded 7-point
|
|
6
|
+
* Gauss estimate `G` (both reuse the same 15 evaluation points, so `G` is
|
|
7
|
+
* "free" once `K` is computed). `|K - G|` is the panel's error estimate; if
|
|
8
|
+
* it exceeds tolerance the interval is bisected and each half is refined
|
|
9
|
+
* recursively. This adapts naturally to endpoint singularities and peaked
|
|
10
|
+
* integrands, unlike a fixed-order Gauss-Legendre rule (see `gaussLegendre5`
|
|
11
|
+
* in `../typed/numeric.ts`, whose Richardson-extrapolation adaptivity still
|
|
12
|
+
* converges slowly on e.g. `x^-1/2` near 0).
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
type f64 = number;
|
|
17
|
+
type i32 = number;
|
|
18
|
+
/** Options for {@link quad}. */
|
|
19
|
+
export interface QuadOptions {
|
|
20
|
+
/** Relative tolerance on each panel's `|K - G|` vs `|K|` (default 1e-10). */
|
|
21
|
+
tol?: f64;
|
|
22
|
+
/** Maximum bisection recursion depth per panel (default 50). */
|
|
23
|
+
maxDepth?: i32;
|
|
24
|
+
}
|
|
25
|
+
/** Result of {@link quad}. */
|
|
26
|
+
export interface QuadResult {
|
|
27
|
+
/** The estimated integral. */
|
|
28
|
+
value: f64;
|
|
29
|
+
/** Sum of the absolute per-panel `|K - G|` error estimates. */
|
|
30
|
+
error: f64;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Adaptive Gauss-Kronrod (G7-K15) numerical integration of `f` over `[a, b]`.
|
|
34
|
+
*
|
|
35
|
+
* Each subinterval is evaluated with the 15-point Kronrod rule and its
|
|
36
|
+
* embedded 7-point Gauss rule; `|K - G|` is the panel's error estimate. A
|
|
37
|
+
* panel whose error exceeds `tol * |K|` (or the absolute floor, for panels
|
|
38
|
+
* near zero) is bisected and each half refined recursively, up to
|
|
39
|
+
* `maxDepth`. This adapts naturally to endpoint singularities and sharply
|
|
40
|
+
* peaked integrands.
|
|
41
|
+
*
|
|
42
|
+
* @param f - Function to integrate
|
|
43
|
+
* @param a - Lower bound
|
|
44
|
+
* @param b - Upper bound
|
|
45
|
+
* @param opts - Options (tol, maxDepth)
|
|
46
|
+
* @returns `{ value, error }` — the estimated integral and summed panel error
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* quad((x) => 4 / (1 + x * x), 0, 1).value; // ~pi
|
|
51
|
+
* quad((x) => 1 / Math.sqrt(x), 0, 1).value; // ~2, despite the endpoint singularity
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function quad(f: (x: f64) => f64, a: f64, b: f64, opts?: QuadOptions): QuadResult;
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=adaptive-quad.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adaptive-quad.d.ts","sourceRoot":"","sources":["../../src/numeric/adaptive-quad.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,KAAK,GAAG,GAAG,MAAM,CAAC;AAClB,KAAK,GAAG,GAAG,MAAM,CAAC;AAElB,gCAAgC;AAChC,MAAM,WAAW,WAAW;IAC1B,6EAA6E;IAC7E,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,gEAAgE;IAChE,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB;AAED,8BAA8B;AAC9B,MAAM,WAAW,UAAU;IACzB,8BAA8B;IAC9B,KAAK,EAAE,GAAG,CAAC;IACX,+DAA+D;IAC/D,KAAK,EAAE,GAAG,CAAC;CACZ;AAgED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,UAAU,CAmBvF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BFGS quasi-Newton minimization of `f: ℝⁿ → ℝ`.
|
|
3
|
+
*
|
|
4
|
+
* Maintains an approximate inverse Hessian `H` (started at the identity) and
|
|
5
|
+
* updates it after every accepted step via the classic BFGS formula:
|
|
6
|
+
*
|
|
7
|
+
* s = x_{k+1} − x_k, y = g_{k+1} − g_k, ρ = 1 / (yᵀs)
|
|
8
|
+
* H ← (I − ρ s yᵀ) H (I − ρ y sᵀ) + ρ s sᵀ
|
|
9
|
+
*
|
|
10
|
+
* The update is skipped (H left unchanged) when `yᵀs ≤ 1e-12` — a near-zero
|
|
11
|
+
* or negative curvature pairing would make H indefinite. The search direction
|
|
12
|
+
* is `d = −H g`, accepted via a backtracking Armijo line search (`c1 = 1e-4`,
|
|
13
|
+
* starting step `α = 1`, halved up to 50 times).
|
|
14
|
+
*
|
|
15
|
+
* `opts.bounds`, if supplied, turns this into a lightweight **projected**
|
|
16
|
+
* BFGS: after every accepted step each coordinate is clipped into its
|
|
17
|
+
* `[lo, hi]` range. This is NOT the full active-set L-BFGS-B method (no
|
|
18
|
+
* distinction between free/active variables in the Hessian update) — it is a
|
|
19
|
+
* simple, effective projection that keeps the iterate feasible.
|
|
20
|
+
*
|
|
21
|
+
* Complements the derivative-free `minimize` (Nelder–Mead): BFGS converges
|
|
22
|
+
* superlinearly on smooth functions using gradient information (analytic or
|
|
23
|
+
* numeric), at the cost of assuming enough smoothness for the gradient/line
|
|
24
|
+
* search to behave.
|
|
25
|
+
*
|
|
26
|
+
* @packageDocumentation
|
|
27
|
+
*/
|
|
28
|
+
type f64 = number;
|
|
29
|
+
/** Options for {@link bfgs}. */
|
|
30
|
+
export interface BfgsOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Analytic gradient `∇f(x)`. If omitted, a central-difference gradient is
|
|
33
|
+
* used with per-coordinate step `h_i = max(1, |x_i|) · cbrt(machine eps)`.
|
|
34
|
+
*/
|
|
35
|
+
grad?: (x: number[]) => number[];
|
|
36
|
+
/**
|
|
37
|
+
* Box constraints `[lo_i, hi_i]` per coordinate. After each accepted step,
|
|
38
|
+
* `x` is clipped into these bounds (projected BFGS — a lightweight
|
|
39
|
+
* approximation of L-BFGS-B, not the full active-set method).
|
|
40
|
+
*/
|
|
41
|
+
bounds?: [f64, f64][];
|
|
42
|
+
/** Convergence tolerance on `‖g‖∞` (default 1e-8). */
|
|
43
|
+
tol?: f64;
|
|
44
|
+
/** Maximum iterations (default 500). */
|
|
45
|
+
maxIter?: number;
|
|
46
|
+
}
|
|
47
|
+
/** Result of {@link bfgs}. */
|
|
48
|
+
export interface BfgsResult {
|
|
49
|
+
/** The minimizer. */
|
|
50
|
+
x: number[];
|
|
51
|
+
/** `f(x)` at the minimizer. */
|
|
52
|
+
fval: f64;
|
|
53
|
+
/** Number of iterations performed. */
|
|
54
|
+
iterations: number;
|
|
55
|
+
/** Whether `‖g‖∞ < tol` was reached within `maxIter`. */
|
|
56
|
+
converged: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Minimize `f: ℝⁿ → ℝ` from `x0` via BFGS quasi-Newton with an Armijo
|
|
60
|
+
* backtracking line search. Uses `opts.grad` if supplied, else a local
|
|
61
|
+
* central-difference gradient. `opts.bounds` clips each accepted step
|
|
62
|
+
* (projected BFGS, not full L-BFGS-B).
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* bfgs((v) => (1 - v[0]) ** 2 + 100 * (v[1] - v[0] ** 2) ** 2, [-1.2, 1])
|
|
66
|
+
* // => { x: ~[1, 1], fval: ~0, ... }
|
|
67
|
+
*/
|
|
68
|
+
export declare function bfgs(f: (x: number[]) => number, x0: number[], opts?: BfgsOptions): BfgsResult;
|
|
69
|
+
export {};
|
|
70
|
+
//# sourceMappingURL=bfgs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bfgs.d.ts","sourceRoot":"","sources":["../../src/numeric/bfgs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,KAAK,GAAG,GAAG,MAAM,CAAC;AAElB,gCAAgC;AAChC,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC;IACjC;;;;OAIG;IACH,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IACtB,sDAAsD;IACtD,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,8BAA8B;AAC9B,MAAM,WAAW,UAAU;IACzB,qBAAqB;IACrB,CAAC,EAAE,MAAM,EAAE,CAAC;IACZ,+BAA+B;IAC/B,IAAI,EAAE,GAAG,CAAC;IACV,sCAAsC;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,SAAS,EAAE,OAAO,CAAC;CACpB;AA+CD;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,GAAE,WAAgB,GAAG,UAAU,CA8EjG"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nonlinear system solver: `fsolve` (damped Newton with a backtracking line
|
|
3
|
+
* search) for `F: R^n -> R^n`. Complements the scalar open root-finders
|
|
4
|
+
* (`./open-root-finders.ts`) and reuses the two Phase 1 foundations:
|
|
5
|
+
* `numericJacobian` (Task 1, central-difference Jacobian) and `linsolve`
|
|
6
|
+
* (`../typed/numeric.ts`, LU with partial pivoting) for the Newton step.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
import { type VectorField } from './numeric-jacobian.js';
|
|
11
|
+
type f64 = number;
|
|
12
|
+
type i32 = number;
|
|
13
|
+
/** Options for `fsolve` / `root`. */
|
|
14
|
+
export interface FsolveOptions {
|
|
15
|
+
/** Absolute tolerance on max|F_i(x)| for convergence (default 1e-10). */
|
|
16
|
+
tol?: f64;
|
|
17
|
+
/** Maximum Newton iterations (default 100). */
|
|
18
|
+
maxIter?: i32;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Solve `F(x) = 0` for `F: R^n -> R^n` via damped Newton's method.
|
|
22
|
+
*
|
|
23
|
+
* At each iterate: compute `J = numericJacobian(F, x)`, solve the Newton
|
|
24
|
+
* step `J * delta = -F(x)` via `linsolve`, then backtrack — try
|
|
25
|
+
* `lambda = 1, 1/2, 1/4, ...` (up to ~20 halvings) and take the largest
|
|
26
|
+
* `lambda` for which `||F(x + lambda*delta)||_2 < ||F(x)||_2`, falling back
|
|
27
|
+
* to `lambda = 1` (a plain Newton step) if no halving improves the residual.
|
|
28
|
+
* Update `x <- x + lambda*delta` and repeat until
|
|
29
|
+
* `max_i |F_i(x)| < tol` (converged) or `maxIter` is exhausted.
|
|
30
|
+
*
|
|
31
|
+
* @param F - Vector field whose root is sought (`F(x) = 0`)
|
|
32
|
+
* @param x0 - Initial guess (length n)
|
|
33
|
+
* @param opts - Options (tol, maxIter)
|
|
34
|
+
* @returns Approximate solution vector x with F(x) ~ 0
|
|
35
|
+
* @throws If the Jacobian is singular (`linsolve` fails) or Newton fails to
|
|
36
|
+
* converge within `maxIter` iterations.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* fsolve((v) => [v[0] ** 2 - v[1], v[0] + v[1] - 2], [0.5, 0.5]) // => ~[1, 1]
|
|
40
|
+
*/
|
|
41
|
+
export declare function fsolve(F: VectorField, x0: readonly number[], opts?: FsolveOptions): number[];
|
|
42
|
+
/** Alias for `fsolve` — `root(F, x0)` solves `F(x) = 0`. */
|
|
43
|
+
export declare const root: typeof fsolve;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=fsolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fsolve.d.ts","sourceRoot":"","sources":["../../src/numeric/fsolve.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAG1E,KAAK,GAAG,GAAG,MAAM,CAAC;AAClB,KAAK,GAAG,GAAG,MAAM,CAAC;AAElB,qCAAqC;AACrC,MAAM,WAAW,aAAa;IAC5B,yEAAyE;IACzE,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,+CAA+C;IAC/C,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAgBD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,GAAE,aAAkB,GAAG,MAAM,EAAE,CAiDhG;AAED,4DAA4D;AAC5D,eAAO,MAAM,IAAI,eAAS,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scalar (1-D) function minimization via Brent's method.
|
|
3
|
+
*
|
|
4
|
+
* Distinct from root-finding (`findRoot`, `newton`, `secant`, `halley`, which
|
|
5
|
+
* solve f(x) = 0): this locates a local minimizer of f over a bounded
|
|
6
|
+
* interval. Combines golden-section search (guaranteed, slow) with parabolic
|
|
7
|
+
* interpolation (fast near a smooth minimum) — the classic algorithm of
|
|
8
|
+
* Brent (1973) / Numerical Recipes §10.2, and the same method behind
|
|
9
|
+
* `scipy.optimize.minimize_scalar(method='bounded')`.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
type f64 = number;
|
|
14
|
+
type i32 = number;
|
|
15
|
+
/**
|
|
16
|
+
* Options for {@link minimizeScalar}.
|
|
17
|
+
*/
|
|
18
|
+
export interface MinimizeScalarOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Interval `[a, b]` to search over (bounded Brent). If omitted, defaults to
|
|
21
|
+
* `[-10, 10]` — a generic finite bracket; supply an explicit bracket for
|
|
22
|
+
* functions whose minimum may lie outside that range.
|
|
23
|
+
*/
|
|
24
|
+
bracket?: [f64, f64];
|
|
25
|
+
/** Convergence tolerance on the interval width (default 1e-8). */
|
|
26
|
+
tol?: f64;
|
|
27
|
+
/** Maximum iterations (default 100). */
|
|
28
|
+
maxIter?: i32;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Result of {@link minimizeScalar}.
|
|
32
|
+
*/
|
|
33
|
+
export interface MinimizeScalarResult {
|
|
34
|
+
/** The minimizer. */
|
|
35
|
+
x: f64;
|
|
36
|
+
/** f(x) at the minimizer. */
|
|
37
|
+
fval: f64;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Minimize a scalar function `f: R -> R` over a bounded interval using
|
|
41
|
+
* Brent's method (golden-section search + parabolic interpolation).
|
|
42
|
+
*
|
|
43
|
+
* If `opts.bracket` is not supplied, the default search interval is
|
|
44
|
+
* `[-10, 10]`.
|
|
45
|
+
*
|
|
46
|
+
* @param f - Function to minimize
|
|
47
|
+
* @param opts - Options (bracket, tol, maxIter)
|
|
48
|
+
* @returns `{ x, fval }` — the minimizer and its function value
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* minimizeScalar(x => (x - 2) ** 2) // => { x: ~2, fval: ~0 }
|
|
52
|
+
* minimizeScalar(Math.sin, { bracket: [0, 2 * Math.PI] }) // => { x: ~3pi/2, fval: ~-1 }
|
|
53
|
+
*/
|
|
54
|
+
export declare function minimizeScalar(f: (x: f64) => f64, opts?: MinimizeScalarOptions): MinimizeScalarResult;
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=minimize-scalar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minimize-scalar.d.ts","sourceRoot":"","sources":["../../src/numeric/minimize-scalar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,KAAK,GAAG,GAAG,MAAM,CAAC;AAClB,KAAK,GAAG,GAAG,MAAM,CAAC;AAQlB;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACrB,kEAAkE;IAClE,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,wCAAwC;IACxC,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,qBAAqB;IACrB,CAAC,EAAE,GAAG,CAAC;IACP,6BAA6B;IAC7B,IAAI,EAAE,GAAG,CAAC;CACX;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAC5B,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,EAClB,IAAI,CAAC,EAAE,qBAAqB,GAC3B,oBAAoB,CAqFtB"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constrained least squares: `nnls` (Lawson–Hanson active-set non-negative
|
|
3
|
+
* least squares) and `lsqBounded` (projected-gradient box-constrained least
|
|
4
|
+
* squares). Both minimize `||Ax - b||_2` subject to simple bound constraints
|
|
5
|
+
* on `x`, complementing the unconstrained `leastSquares` (`../typed/numeric.ts`).
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/** Options shared by `nnls` and `lsqBounded`. */
|
|
10
|
+
export interface NnlsOptions {
|
|
11
|
+
/** Convergence tolerance (default 1e-10). */
|
|
12
|
+
tol?: number;
|
|
13
|
+
/** Maximum iterations (default `3 * n`). */
|
|
14
|
+
maxIter?: number;
|
|
15
|
+
}
|
|
16
|
+
/** Options for `lsqBounded` (same shape as `NnlsOptions`, kept as a distinct alias for clarity). */
|
|
17
|
+
export type LsqBoundedOptions = NnlsOptions;
|
|
18
|
+
/** Result of `nnls` / `lsqBounded`: the solution and its residual norm. */
|
|
19
|
+
export interface NnlsResult {
|
|
20
|
+
/** Solution vector x. */
|
|
21
|
+
x: number[];
|
|
22
|
+
/** `||Ax - b||_2` at the returned solution. */
|
|
23
|
+
residual: number;
|
|
24
|
+
}
|
|
25
|
+
/** Alias for `NnlsResult` (used by `lsqBounded`). */
|
|
26
|
+
export type LsqBoundedResult = NnlsResult;
|
|
27
|
+
/**
|
|
28
|
+
* Non-negative least squares: `min ||Ax - b||_2 s.t. x >= 0`, via the
|
|
29
|
+
* Lawson–Hanson active-set algorithm.
|
|
30
|
+
*
|
|
31
|
+
* Maintains a "passive" set `P` of coordinates allowed to be nonzero (all
|
|
32
|
+
* others held at 0). Each outer iteration adds to `P` the inactive index
|
|
33
|
+
* with the most positive gradient component `w_j = (A^T(b - Ax))_j`, solves
|
|
34
|
+
* the unconstrained least-squares problem restricted to the columns in `P`
|
|
35
|
+
* (via `leastSquares`), and — if that restricted solution has any
|
|
36
|
+
* non-positive component — walks back along the line from the current `x`
|
|
37
|
+
* toward it until the first such component would hit zero, dropping that
|
|
38
|
+
* index from `P` and re-solving. Terminates when no inactive index has a
|
|
39
|
+
* positive gradient (KKT optimality) or `maxIter` is exhausted.
|
|
40
|
+
*
|
|
41
|
+
* @param A - Matrix (m x n)
|
|
42
|
+
* @param b - Right-hand side (length m)
|
|
43
|
+
* @param opts - Options (tol, maxIter; default maxIter = 3n)
|
|
44
|
+
* @returns `{ x, residual }` with `x >= 0` (up to `tol`) and `residual = ||Ax - b||_2`
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* nnls([[1, 0], [0, 1]], [3, -2]) // => { x: [3, 0], residual: 2 }
|
|
48
|
+
*/
|
|
49
|
+
export declare function nnls(A: number[][], b: number[], opts?: NnlsOptions): NnlsResult;
|
|
50
|
+
/**
|
|
51
|
+
* Box-constrained least squares: `min ||Ax - b||_2 s.t. lower <= x <= upper`,
|
|
52
|
+
* via projected-gradient descent.
|
|
53
|
+
*
|
|
54
|
+
* Each iteration computes the gradient `g = A^T(Ax - b)` of the smooth
|
|
55
|
+
* objective `f(x) = (1/2)||Ax - b||^2`, takes a candidate step
|
|
56
|
+
* `x - alpha*g` projected (clipped) into the box, and backtracks
|
|
57
|
+
* (`alpha /= 2`) until the projected step does not increase `f`. Converges
|
|
58
|
+
* when the projected-gradient norm `||x - clip(x - g, lower, upper)||` is
|
|
59
|
+
* below `tol`.
|
|
60
|
+
*
|
|
61
|
+
* @param A - Matrix (m x n)
|
|
62
|
+
* @param b - Right-hand side (length m)
|
|
63
|
+
* @param lower - Per-component lower bounds (length n)
|
|
64
|
+
* @param upper - Per-component upper bounds (length n)
|
|
65
|
+
* @param opts - Options (tol, maxIter; default maxIter = max(200, 20n))
|
|
66
|
+
* @returns `{ x, residual }` with `lower <= x <= upper` and `residual = ||Ax - b||_2`
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* lsqBounded([[1, 0], [0, 1]], [5, -3], [0, 0], [2, 2]) // => { x: [2, 0], residual: ... }
|
|
70
|
+
*/
|
|
71
|
+
export declare function lsqBounded(A: number[][], b: number[], lower: number[], upper: number[], opts?: LsqBoundedOptions): LsqBoundedResult;
|
|
72
|
+
//# sourceMappingURL=nnls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nnls.d.ts","sourceRoot":"","sources":["../../src/numeric/nnls.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,iDAAiD;AACjD,MAAM,WAAW,WAAW;IAC1B,6CAA6C;IAC7C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,oGAAoG;AACpG,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC;AAE5C,2EAA2E;AAC3E,MAAM,WAAW,UAAU;IACzB,yBAAyB;IACzB,CAAC,EAAE,MAAM,EAAE,CAAC;IACZ,+CAA+C;IAC/C,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,qDAAqD;AACrD,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC;AA8B1C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,GAAE,WAAgB,GAAG,UAAU,CA6EnF;AAOD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,UAAU,CACxB,CAAC,EAAE,MAAM,EAAE,EAAE,EACb,CAAC,EAAE,MAAM,EAAE,EACX,KAAK,EAAE,MAAM,EAAE,EACf,KAAK,EAAE,MAAM,EAAE,EACf,IAAI,GAAE,iBAAsB,GAC3B,gBAAgB,CAgElB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Numeric Jacobian of a vector-valued function `f: R^n -> R^m` via central
|
|
3
|
+
* differences. Complements the symbolic `jacobian(exprs, vars, scope)` in
|
|
4
|
+
* `typed/cas.ts` — that path requires expression strings and throws on a
|
|
5
|
+
* plain numeric function (`exprs.map is not a function`). This is the
|
|
6
|
+
* foundation for numeric root-finding (`fsolve`, Phase 1 Task 3).
|
|
7
|
+
*/
|
|
8
|
+
/** A vector field ℝⁿ → ℝᵐ. */
|
|
9
|
+
export type VectorField = (x: number[]) => number[];
|
|
10
|
+
export interface NumericJacobianOptions {
|
|
11
|
+
/** Absolute step override. Default: per-coordinate relative step (see below). */
|
|
12
|
+
h?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Central-difference Jacobian: `J[i][j] = ∂f_i/∂x_j = (f_i(x0 + h·e_j) − f_i(x0 − h·e_j)) / (2h)`.
|
|
16
|
+
*
|
|
17
|
+
* `f` need not be square (`m = f(x0).length` rows, `n = x0.length` columns).
|
|
18
|
+
* The per-coordinate step defaults to `h = max(1, |x0[j]|) * cbrt(eps)`
|
|
19
|
+
* (eps = 2.22e-16, i.e. Number.EPSILON), the standard relative step for
|
|
20
|
+
* central differences (~6e-6 relative) that balances truncation error
|
|
21
|
+
* (O(h^2)) against floating-point round-off (O(eps/h)).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* numericJacobian((v) => [v[0] ** 2 + v[1], v[0] * v[1]], [1, 2])
|
|
25
|
+
* // => [[2, 1], [2, 1]]
|
|
26
|
+
*/
|
|
27
|
+
export declare function numericJacobian(f: VectorField, x0: readonly number[], opts?: NumericJacobianOptions): number[][];
|
|
28
|
+
//# sourceMappingURL=numeric-jacobian.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numeric-jacobian.d.ts","sourceRoot":"","sources":["../../src/numeric/numeric-jacobian.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,8BAA8B;AAC9B,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC;AAEpD,MAAM,WAAW,sBAAsB;IACrC,iFAAiF;IACjF,CAAC,CAAC,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC7B,CAAC,EAAE,WAAW,EACd,EAAE,EAAE,SAAS,MAAM,EAAE,EACrB,IAAI,GAAE,sBAA2B,GAChC,MAAM,EAAE,EAAE,CA0BZ"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Open (non-bracketing) scalar root-finders.
|
|
3
|
+
*
|
|
4
|
+
* Complements the bracketing `findRoot` (bisection/Brent, `../typed/numeric.ts`)
|
|
5
|
+
* with classic open methods that iterate from a starting point (or two)
|
|
6
|
+
* without requiring a sign-change bracket: Newton–Raphson, secant, and
|
|
7
|
+
* Halley's method (cubic convergence).
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
type f64 = number;
|
|
12
|
+
type i32 = number;
|
|
13
|
+
/**
|
|
14
|
+
* Options for Newton's method.
|
|
15
|
+
*/
|
|
16
|
+
export interface NewtonOptions {
|
|
17
|
+
/** Analytic derivative f'(x). If omitted, a central-difference estimate is used. */
|
|
18
|
+
fprime?: (x: f64) => f64;
|
|
19
|
+
/** Absolute tolerance for convergence (default 1e-12) */
|
|
20
|
+
tol?: f64;
|
|
21
|
+
/** Maximum iterations (default 100) */
|
|
22
|
+
maxIter?: i32;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Find a root of f(x) = 0 via Newton–Raphson iteration:
|
|
26
|
+
* `x_{k+1} = x_k - f(x_k) / f'(x_k)`.
|
|
27
|
+
*
|
|
28
|
+
* If `opts.fprime` is not supplied, the derivative is estimated by a
|
|
29
|
+
* central difference with step `h = max(1, |x|) * cbrt(eps)`.
|
|
30
|
+
*
|
|
31
|
+
* @param f - Function whose root is sought
|
|
32
|
+
* @param x0 - Initial guess
|
|
33
|
+
* @param opts - Options (fprime, tol, maxIter)
|
|
34
|
+
* @returns Approximate root
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* newton(x => x ** 2 - 2, 1) // => ~1.4142135623730951
|
|
38
|
+
*/
|
|
39
|
+
export declare function newton(f: (x: f64) => f64, x0: f64, opts?: NewtonOptions): f64;
|
|
40
|
+
/**
|
|
41
|
+
* Options for the secant method.
|
|
42
|
+
*/
|
|
43
|
+
export interface SecantOptions {
|
|
44
|
+
/** Absolute tolerance for convergence (default 1e-12) */
|
|
45
|
+
tol?: f64;
|
|
46
|
+
/** Maximum iterations (default 100) */
|
|
47
|
+
maxIter?: i32;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Find a root of f(x) = 0 via the secant method:
|
|
51
|
+
* `x_{k+1} = x_k - f(x_k) (x_k - x_{k-1}) / (f(x_k) - f(x_{k-1}))`.
|
|
52
|
+
*
|
|
53
|
+
* Requires no derivative, but two initial estimates.
|
|
54
|
+
*
|
|
55
|
+
* @param f - Function whose root is sought
|
|
56
|
+
* @param x0 - First initial estimate
|
|
57
|
+
* @param x1 - Second initial estimate
|
|
58
|
+
* @param opts - Options (tol, maxIter)
|
|
59
|
+
* @returns Approximate root
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* secant(x => x ** 2 - 2, 1, 2) // => ~1.4142135623730951
|
|
63
|
+
*/
|
|
64
|
+
export declare function secant(f: (x: f64) => f64, x0: f64, x1: f64, opts?: SecantOptions): f64;
|
|
65
|
+
/**
|
|
66
|
+
* Options for Halley's method.
|
|
67
|
+
*/
|
|
68
|
+
export interface HalleyOptions {
|
|
69
|
+
/** Analytic first derivative f'(x). If omitted, estimated via central difference. */
|
|
70
|
+
fprime?: (x: f64) => f64;
|
|
71
|
+
/** Analytic second derivative f''(x). If omitted, estimated via central difference. */
|
|
72
|
+
fprime2?: (x: f64) => f64;
|
|
73
|
+
/** Absolute tolerance for convergence (default 1e-12) */
|
|
74
|
+
tol?: f64;
|
|
75
|
+
/** Maximum iterations (default 100) */
|
|
76
|
+
maxIter?: i32;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Find a root of f(x) = 0 via Halley's method (cubic convergence):
|
|
80
|
+
* `x_{k+1} = x_k - 2 f f' / (2 f'^2 - f f'')`.
|
|
81
|
+
*
|
|
82
|
+
* If `opts.fprime` / `opts.fprime2` are not supplied, both derivatives are
|
|
83
|
+
* estimated by central differences with step `h = max(1, |x|) * cbrt(eps)`.
|
|
84
|
+
*
|
|
85
|
+
* @param f - Function whose root is sought
|
|
86
|
+
* @param x0 - Initial guess
|
|
87
|
+
* @param opts - Options (fprime, fprime2, tol, maxIter)
|
|
88
|
+
* @returns Approximate root
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* halley(x => x ** 3 - 2, 1) // => ~1.2599210498948732
|
|
92
|
+
*/
|
|
93
|
+
export declare function halley(f: (x: f64) => f64, x0: f64, opts?: HalleyOptions): f64;
|
|
94
|
+
export {};
|
|
95
|
+
//# sourceMappingURL=open-root-finders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-root-finders.d.ts","sourceRoot":"","sources":["../../src/numeric/open-root-finders.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,KAAK,GAAG,GAAG,MAAM,CAAC;AAClB,KAAK,GAAG,GAAG,MAAM,CAAC;AAelB;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,oFAAoF;IACpF,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC;IACzB,yDAAyD;IACzD,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,uCAAuC;IACvC,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,GAAG,CAuB7E;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,yDAAyD;IACzD,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,uCAAuC;IACvC,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,GAAG,CA2BtF;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,qFAAqF;IACrF,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC;IACzB,uFAAuF;IACvF,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC;IAC1B,yDAAyD;IACzD,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,uCAAuC;IACvC,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,GAAG,CA2B7E"}
|
package/dist/typed/cas.d.ts
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import { parse } from '../factories/evaluate.js';
|
|
23
23
|
import { Complex } from '@danielsimonjr/mathts-core';
|
|
24
|
+
import { type VectorField } from '../numeric/numeric-jacobian.js';
|
|
24
25
|
type f64 = number;
|
|
25
26
|
type MathNode = ReturnType<typeof parse>;
|
|
26
27
|
/**
|
|
@@ -109,17 +110,25 @@ export declare function gradientSymbolic(expr: string, vars: string[], scope: Re
|
|
|
109
110
|
/**
|
|
110
111
|
* Compute the Jacobian matrix of a vector-valued function.
|
|
111
112
|
*
|
|
112
|
-
*
|
|
113
|
+
* Polymorphic: symbolic when `exprs` is an array of expression strings
|
|
114
|
+
* (J[i][j] = partial derivative of exprs[i] with respect to vars[j]);
|
|
115
|
+
* numeric (central differences) when `exprs` is a plain function
|
|
116
|
+
* `f: number[] => number[]` — dispatches to `numericJacobian(f, x0)`.
|
|
113
117
|
*
|
|
114
|
-
* @param exprs - Array of expression strings (vector field components)
|
|
115
|
-
*
|
|
116
|
-
* @param
|
|
118
|
+
* @param exprs - Array of expression strings (vector field components), OR a
|
|
119
|
+
* numeric vector field `f: (x: number[]) => number[]`
|
|
120
|
+
* @param vars - Variable names (symbolic), OR the numeric evaluation point `x0`
|
|
121
|
+
* @param scope - Variable values at which to evaluate (symbolic path only)
|
|
117
122
|
* @returns 2D array (matrix) of partial derivatives
|
|
118
123
|
*
|
|
119
124
|
* @example
|
|
120
125
|
* jacobian(['x*y', 'x^2'], ['x', 'y'], { x: 2, y: 3 })
|
|
121
126
|
* // => [[3, 2], [4, 0]]
|
|
127
|
+
* @example
|
|
128
|
+
* jacobian((v) => [v[0] * v[1], v[0] ** 2], [2, 3])
|
|
129
|
+
* // => [[3, 2], [4, 0]] (numeric, central differences)
|
|
122
130
|
*/
|
|
131
|
+
export declare function jacobian(exprs: VectorField, vars: number[]): f64[][];
|
|
123
132
|
export declare function jacobian(exprs: string[], vars: string[], scope: Record<string, f64>): f64[][];
|
|
124
133
|
/**
|
|
125
134
|
* Compute the Laplacian of a scalar field.
|
package/dist/typed/cas.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cas.d.ts","sourceRoot":"","sources":["../../src/typed/cas.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;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C;AAkKhF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;AACjF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;AA8EpG;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;AAC3D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;AA0C9E;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;AAC3D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC"}
|
package/dist/typed/numeric.d.ts
CHANGED
|
@@ -100,13 +100,17 @@ export declare function globalMinimize(f: (x: number[]) => f64, bounds: [number,
|
|
|
100
100
|
*/
|
|
101
101
|
export declare function leastSquares(A: number[][], b: number[]): number[];
|
|
102
102
|
/**
|
|
103
|
-
* Adaptive numerical integration
|
|
104
|
-
*
|
|
103
|
+
* Adaptive numerical integration via Gauss-Kronrod (G7-K15) quadrature (see
|
|
104
|
+
* {@link quad} in `../numeric/adaptive-quad.js`). Previously used a fixed
|
|
105
|
+
* 5-point Gauss-Legendre panel with Richardson-extrapolation adaptivity,
|
|
106
|
+
* which converged slowly on endpoint singularities (e.g. `x^-1/2` near 0,
|
|
107
|
+
* ~1.7e-6 error); G7-K15's embedded error estimate resolves those panels
|
|
108
|
+
* directly, down to ~1e-10.
|
|
105
109
|
*
|
|
106
110
|
* @param f - Function to integrate
|
|
107
111
|
* @param a - Lower bound
|
|
108
112
|
* @param b - Upper bound
|
|
109
|
-
* @param opts - Options (tol,
|
|
113
|
+
* @param opts - Options (tol, maxDepth for max subdivisions)
|
|
110
114
|
* @returns Approximate integral
|
|
111
115
|
*/
|
|
112
116
|
export declare function nintegrate(f: (x: f64) => f64, a: f64, b: f64, opts?: {
|
|
@@ -363,15 +367,36 @@ export declare function padeApproximant(coeffs: number[], m: i32, n: i32): {
|
|
|
363
367
|
*/
|
|
364
368
|
export declare function quadprog(H: number[][], f: number[], A: number[][], b: number[]): number[];
|
|
365
369
|
/**
|
|
366
|
-
*
|
|
367
|
-
*
|
|
370
|
+
* Options form of {@link linprog}: minimize c^T x subject to A_ub x <= b_ub,
|
|
371
|
+
* A_eq x = b_eq, and per-variable bounds.
|
|
372
|
+
*/
|
|
373
|
+
export interface LinprogOptions {
|
|
374
|
+
A_ub?: number[][];
|
|
375
|
+
b_ub?: number[];
|
|
376
|
+
A_eq?: number[][];
|
|
377
|
+
b_eq?: number[];
|
|
378
|
+
/** Per-variable [lower, upper] bounds; null = unbounded. Default: [0, null] for every variable. */
|
|
379
|
+
bounds?: readonly (readonly [number | null, number | null])[];
|
|
380
|
+
}
|
|
381
|
+
/** Result of the options form of {@link linprog}. */
|
|
382
|
+
export interface LinprogResult {
|
|
383
|
+
x: number[];
|
|
384
|
+
fun: number;
|
|
385
|
+
success: boolean;
|
|
386
|
+
status: 'optimal' | 'infeasible' | 'unbounded';
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Linear programming: minimize c^T x.
|
|
368
390
|
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
391
|
+
* Two overloads:
|
|
392
|
+
* - Legacy positional form `linprog(c, A_ub, b_ub)` — subject to `A_ub x <= b_ub`,
|
|
393
|
+
* `x >= 0`; returns the solution vector `x` (or `null` if unbounded).
|
|
394
|
+
* - Options form `linprog(c, { A_ub, b_ub, A_eq, b_eq, bounds })` — a two-phase
|
|
395
|
+
* simplex supporting equality constraints, variable bounds, and negative-RHS
|
|
396
|
+
* rows; returns `{ x, fun, success, status }`.
|
|
373
397
|
*/
|
|
374
|
-
export declare function linprog(c: number[],
|
|
398
|
+
export declare function linprog(c: number[], A_ub: number[][], b_ub: number[]): number[] | null;
|
|
399
|
+
export declare function linprog(c: number[], opts: LinprogOptions): LinprogResult;
|
|
375
400
|
/**
|
|
376
401
|
* Simple 1D PDE solver using finite differences (heat equation).
|
|
377
402
|
*
|