/** * Complex matrix functions — `funm`/`cosm`/`sinm` for a general real matrix. * * `funm(A, f)` evaluates a scalar analytic function `f` at a square matrix * `A`, returning the complex matrix `f(A)`. Unlike `sqrtm`/`matrixLogm` * (which only handle real matrices whose spectrum stays on the principal * branch — positive reals for sqrt/log), `funm` accepts any real spectrum * (negative, complex-conjugate pairs, …) because the result is allowed to be * complex-valued. * * Algorithm (diagonalizable matrices with distinct eigenvalues): * - If `A` is diagonal, `f(A)` is exact and trivial: apply `f` to each * diagonal entry (handles repeated eigenvalues fine, since a diagonal * matrix is always diagonalizable regardless of eigenvalue multiplicity). * - Otherwise, compute `A`'s eigenvalues `λ_1, …, λ_n` (via the shared * `@danielsimonjr/mathts-matrix` `eig` — Householder + Francis QR) and, * when they are all distinct, apply the Lagrange-Sylvester interpolation * formula for a diagonalizable matrix with simple spectrum: * * f(A) = Σ_i f(λ_i) · L_i(A), L_i(A) = Π_{j≠i} (A − λ_j I) / (λ_i − λ_j) * * evaluated in complex arithmetic (`A` embedded with zero imaginary * part). This needs only eigenvalues, not eigenvectors, and is exact for * any polynomial or entire function `f` (cos, sin, sqrt, exp, log, …) * whenever the spectrum is simple. * * Defective / repeated-eigenvalue matrices (confluent Hermite interpolation): * - When eigenvalues repeat (or cluster within `EIGENVALUE_DISTINCT_REL_TOL`), * `f(A)` depends on `f` AND its derivatives at each repeated eigenvalue — * for a Jordan block `J = λI + N` (N nilpotent, `N^s = 0`), * f(J) = Σ_{k=0}^{s-1} f^(k)(λ)/k! · N^k. * `funm` builds the confluent node list (each distinct eigenvalue repeated * to its multiplicity) and evaluates the Newton divided-difference form * f(A) = Σ_k f[z_0,…,z_k] · Π_{i 5 with no analytic derivatives). * * @packageDocumentation */ /** * A complex number as a plain `{re, im}` pair. Consolidated onto * `@danielsimonjr/mathts-core/internal`'s byte-identical `ComplexValue` (see * docs/Architecture/duplicate-symbols.json) rather than redeclared locally. */ import type { ComplexValue } from '@danielsimonjr/mathts-core/internal'; export type { ComplexValue }; /** A complex-valued dense matrix, stored as parallel real/imaginary 2-D arrays. */ export interface ComplexMatrix { re: number[][]; im: number[][]; } /** A scalar analytic function to be applied to a matrix's spectrum. */ export type ScalarComplexFunction = (z: ComplexValue) => ComplexValue; /** * Evaluate the matrix function `f(A)` for a square real matrix `A`, returning * a complex matrix `{re, im}`. * * Supports: * - diagonal matrices unconditionally (exact, elementwise); * - diagonalizable matrices with pairwise-distinct eigenvalues * (Lagrange-Sylvester interpolation — the fast simple-spectrum branch); * - defective / non-diagonalizable matrices with repeated (or numerically * clustered) eigenvalues, via **confluent Hermite interpolation** (Newton * divided differences over repeated eigenvalue nodes). A matrix function of * a defective matrix depends on `f` AND its derivatives at each repeated * eigenvalue (for a Jordan block `J = λI + N`, `f(J) = Σ_k f^(k)(λ)/k! · N^k`), * so this branch needs derivatives of `f`: pass them analytically via * `fDerivs` for machine precision, or they are approximated numerically. * * Throws (rather than return a wrong/`NaN` answer) when `f` or its derivatives * are singular at a repeated eigenvalue (e.g. `sqrt`/`log` at 0), or when a * needed numerical derivative order exceeds the built-in stencils. * * @param A - Square real matrix, as a plain 2-D array. * @param f - Scalar function to apply to the spectrum, e.g. `cos`, `sin`, * `sqrt`, `exp`, `log`, extended to complex arguments. * @param fDerivs - Optional analytic derivatives of `f`: `fDerivs[k]` is * `f^(k+1)`. Needed only for defective matrices; when omitted, derivatives * are computed by finite differences (~1e-6 accuracy). Additive and * non-breaking — distinct-spectrum inputs never consult it. * @returns `{ re, im }` — the (possibly complex) matrix `f(A)`. */ export declare function funm(A: number[][], f: ScalarComplexFunction, fDerivs?: ScalarComplexFunction[]): ComplexMatrix; /** Complex cosine: `cos(z) = cos(re)cosh(im) - i sin(re)sinh(im)`. */ export declare function complexCos(z: ComplexValue): ComplexValue; /** Complex sine: `sin(z) = sin(re)cosh(im) + i cos(re)sinh(im)`. */ export declare function complexSin(z: ComplexValue): ComplexValue; /** Matrix cosine `cos(A)`, via {@link funm} with {@link complexCos}. Passes * exact analytic derivatives so defective matrices are machine-precise. */ export declare function cosm(A: number[][]): ComplexMatrix; /** Matrix sine `sin(A)`, via {@link funm} with {@link complexSin}. Passes * exact analytic derivatives so defective matrices are machine-precise. */ export declare function sinm(A: number[][]): ComplexMatrix; //# sourceMappingURL=matrix-functions.d.ts.map