Skip to content

Nerdamer: Solving Equations

JS Calc leverages Nerdamer.js to solve various types of algebraic equations symbolically.

Solve Single Equations: solve()

The solve() command is used to find the roots of a single polynomial equation with respect to a specified variable.

Syntax: solve(equation, variable)

  • equation: The equation to solve (e.g., x^2 - 4 = 0).
  • variable: The variable to solve for (e.g., x).

Capabilities & Output:

  • Solves for roots of polynomial equations (linear, quadratic, cubic, etc.).
  • Returns solutions as a comma-separated string, often enclosed in square brackets by Nerdamer if multiple solutions exist (JS Calc may simplify this for single results).
  • Can return numerical, symbolic, or complex roots.

Examples:

> solve(2x + 4 = 10, x)
 3

> solve(a^2 - 9 = 0, a)
 3, -3

> solve(y^3 + 8 = 0, y)
 -2, 1-1.7320508075688772i, 1+1.7320508075688772i

Known Limitations for solve():

  • Transcendental Equations: Equations involving functions like sin(x), cos(x), log(x), exp(x) (e.g., sin(x)=0.5) are generally not solved symbolically by this specific solve command and may return [No solution or result].
  • General Symbolic Forms: For some equations with multiple undefined symbolic constants (e.g., solve(ax+b=c, x)), it may not return a rearranged symbolic solution like (c-b)/a.

Solve Systems of Equations: solveEquations()

The solveEquations() command is designed to solve systems of simultaneous equations (primarily linear, with some capability for non-linear systems).

Syntax (Special Parsing by JS Calc): solveEquations([equation1, equation2, ...], [variable1, variable2, ...])

  • The first argument is a comma-separated list of equations, enclosed in square brackets [].
  • The second argument is a comma-separated list of variables to solve for, also enclosed in [].
  • Important: Do not individually double-quote the equations or variables within these lists.

Output:

  • Typically returns solutions in an interleaved format (e.g., var1, solution1, var2, solution2, ...).

Examples:

> solveEquations([x+y=5, x-y=1], [x,y])
 x, 3, y, 2

> solveEquations([2a-b=8, a+2b=9], [a,b])
 a, 5, b, 2

Rearrange Equation: solveFor()

The solveFor() command attempts to rearrange a single equation to make a specified variable the subject (isolate it on one side).

Syntax (Special Parsing by JS Calc): solveFor(equation, variable)

  • equation: The single equation string.
  • variable: The string name of the variable to solve for.

Output: * Returns the expression for the isolated variable. If multiple forms are possible (e.g., from a quadratic), they may be comma-separated.

Examples:

> solveFor(y = m*x + c, x)
 (-c+y)/m

> solveFor(PV = nRT, T)
 PVn^(-1)R^(-1) // or PV/(nR)

> solveFor(x^2 + y^2 = r^2, y)
 sqrt(-x^2+r^2), -sqrt(-x^2+r^2)