Searches a fixed interval for real roots of a univariate expression.

remarks

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): RootMethod

Refines a bracket using Brent's combination of bisection, secant, and inverse-quadratic interpolation.

Parameters

NameTypeDescription
aDecimalFirst bracket endpoint.
bDecimalSecond 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): FunctionSolverConstructor

Creates a real-root solver for the configured search interval.

throws

core!UnsupportedOperationError If variable is omitted and the expression contains more than one variable.

Parameters

NameTypeDescription
funcstring | ExpressionExpression to evaluate, or a string parsed as an Expression.
variablestringVariable to substitute. When omitted, the expression must contain at most one variable.
optionsFunctionSolverOptionsSearch interval, refinement method, and tolerances.

Returns

FunctionSolver

derivativeStep: DecimalProperty

No description is available yet.

df(x: Decimal, h: Decimal): DecimalMethod

Approximates the derivative with a central difference.

Parameters

NameTypeDescription
xDecimal—
hDecimal—

Returns

Decimal

evaluate(at: string | number | Decimal): DecimalMethod

Evaluates the configured expression at a real value.

throws

core!UnexpectedInputError If evaluation does not produce a scalar Expression.

Parameters

NameTypeDescription
atstring | number | Decimal—

Returns

Decimal

func: ExpressionProperty

No description is available yet.

lowerBound: DecimalProperty

No description is available yet.

maxIters: numberProperty

No description is available yet.

maxRoots: numberProperty

No description is available yet.

NewtonRaphson(guess: Decimal): { … } | { … }Method

Refines a root from an initial guess using Newton-Raphson and a numerical derivative.

Parameters

NameTypeDescription
guessDecimal—

Returns

{ … } | { … } — Refinement metadata, including non-convergence or a zero derivative.

roots(): Expression[]Method

Searches 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: numberProperty

No description is available yet.

tolerance: DecimalProperty

No description is available yet.

upperBound: DecimalProperty

No description is available yet.

variable: stringProperty

No description is available yet.

verbose: booleanProperty

No description is available yet.