Function reference · Solving

solve

Solves an expression or equation for a variable and returns the solutions as a SolutionSet.

Nerdamer solves exact symbolic equations when supported, including polynomial equations with symbolic parameters. Expressions are treated as equations equal to zero; explicit equations can be supplied directly.

The solver returns distinct solutions in a SolutionSet rather than a plain JavaScript array.

Examples

These examples use Nerdamer Notation.

Solve a quadratic with two exact roots.

solve(6-5*x+x^2,x)
// → {3, 2}

Return all distinct roots of a factorable cubic.

solve(-6+11*x-6*x^2+x^3,x)
// → {1, 2, 3}

Keep symbolic parameters in the quadratic formula.

solve(a*x^2+b*x+c,x)
// → {(1/2)*a^-1*(-b+(b^2-4*a*c)^(1/2)), (1/2)*a^-1*(-b-(b^2-4*a*c)^(1/2))}

Interfaces

The same operation is available through the interfaces below.

Nerdamer Notation · nerdamer API · Direct API

Nerdamer Notation

Use this form inside input passed to nerdamer(...).

solve(expressionOrEquation, variable)

Parameters

  • expressionOrEquation — Expression or equation to solve.
  • variable — Variable to solve for.

nerdamer.solve

Call the operation through the default nerdamer import.

nerdamer.solve(input: ExpressionInput | Equation, variable?: ExpressionInput, _options?: FunctionSolverOptions): SolutionSet

Parameters

NameTypeDescription
inputExpressionInput | EquationExpression or equation to solve.
variableExpressionInputVariable to solve for. When omitted, input preparation infers it where possible.
_optionsFunctionSolverOptionsReserved numerical-solver options.

Returns

SolutionSet — A SolutionSet. The special `all` expression represents an identity that is true for every value of the variable.

Browse the nerdamer API →

Direct JavaScript / TypeScript API

Import the operation directly from its package entry point.

import { solve } from 'nerdamer/solve';
solve(input: ExpressionInput | Equation, variable?: ExpressionInput, _options?: FunctionSolverOptions): SolutionSet

Parameters

NameTypeDescription
inputExpressionInput | EquationExpression or equation to solve.
variableExpressionInputVariable to solve for. When omitted, input preparation infers it where possible.
_optionsFunctionSolverOptionsReserved numerical-solver options.

Returns

SolutionSet — A SolutionSet. The special `all` expression represents an identity that is true for every value of the variable.

Browse nerdamer/solve

← Back to Reference