FunctionSolver
Searches a fixed interval for real roots of a univariate expression.
roots scans the configured interval from its center toward both
endpoints. It refines sign-changing intervals with Brent's method or
Newton-Raphson, verifies residuals, merges nearby results, and returns roots
in ascending order. This is a heuristic search: an even-multiplicity root
can be missed unless a scan point lands sufficiently close to it, and
periodic functions are limited by both the interval and maxRoots.
Calculations use the ambient decimal.js precision. An Expression supplied
to the constructor is retained rather than copied, and the public settings
may be adjusted before a search.
Examples
const solver = new FunctionSolver('cos(x)-x', 'x', {
lowerBound: 0,
upperBound: 1,
});
const roots = solver.roots();Members
Brent(a: Decimal, b: Decimal): RootMethodRefines a bracket using Brent's combination of bisection, secant, and inverse-quadratic interpolation.
Parameters
| Name | Type | Description |
|---|---|---|
a | Decimal | First bracket endpoint. |
b | Decimal | Second bracket endpoint. |
Returns
Root — Refinement metadata. Invalid brackets and exhausted iterations are
represented in the returned Root; they are not thrown.
FunctionSolver(func: string | Expression, variable?: string, options: FunctionSolverOptions): FunctionSolverConstructorCreates a real-root solver for the configured search interval.
core!UnsupportedOperationError If variable is omitted and the
expression contains more than one variable.
Parameters
| Name | Type | Description |
|---|---|---|
func | string | Expression | Expression to evaluate, or a string parsed as an Expression. |
variable | string | Variable to substitute. When omitted, the expression must contain at most one variable. |
options | FunctionSolverOptions | Search interval, refinement method, and tolerances. |
Returns
derivativeStep: DecimalPropertyNo description is available yet.
df(x: Decimal, h: Decimal): DecimalMethodApproximates the derivative with a central difference.
Parameters
| Name | Type | Description |
|---|---|---|
x | Decimal | — |
h | Decimal | — |
Returns
Decimal
evaluate(at: string | number | Decimal): DecimalMethodEvaluates the configured expression at a real value.
core!UnexpectedInputError If evaluation does not produce a scalar Expression.
Parameters
| Name | Type | Description |
|---|---|---|
at | string | number | Decimal | — |
Returns
Decimal
func: ExpressionPropertyNo description is available yet.
lowerBound: DecimalPropertyNo description is available yet.
maxIters: numberPropertyNo description is available yet.
maxRoots: numberPropertyNo description is available yet.
method: RootFindingMethodPropertyNo description is available yet.
NewtonRaphson(guess: Decimal): { … } | { … }MethodRefines a root from an initial guess using Newton-Raphson and a numerical derivative.
Parameters
| Name | Type | Description |
|---|---|---|
guess | Decimal | — |
Returns
{ … } | { … } — Refinement metadata, including non-convergence or a zero derivative.
roots(): Expression[]MethodSearches the configured interval for real roots.
Returns
Expression[] — Verified, deduplicated roots in ascending order, limited by
maxRoots. Failed evaluations and failed refinements are skipped.
stepSize: numberPropertyNo description is available yet.
tolerance: DecimalPropertyNo description is available yet.
upperBound: DecimalPropertyNo description is available yet.
variable: stringPropertyNo description is available yet.
verbose: booleanPropertyNo description is available yet.
