solveeqs
Solves a system of equations and returns the solutions.
It solves linear and nonlinear systems, exactly where it can and numerically otherwise. Systems with free variables, complex coefficients, more equations than unknowns, or trigonometric terms all work.
In Notation it is solveeqs; in JavaScript it is solveSystem, which can also take the list of unknowns, so other symbols are treated as parameters.
The result is a vector with one dictionary per solution, such as [{x => 2, y => 1}]. When a linear system has infinitely many solutions, the answer is written in terms of its free variables.
Notation
solveeqs(arg1)
Write it in an expression: nerdamer('solveeqs([x+y+z=6,x-y=2])'), or in the Playground.
nerdamer.solveeqs
nerdamer.solveSystem(equations: Vector | Equation | ExpressionInput | Equation | ExpressionInput[], variables?: string[]): Vector
A method on the default import. Arguments can be strings, as in Notation.
import { solveSystem }
import { solveSystem } from 'nerdamer/solve';
solveSystem(equations: Vector | Equation | ExpressionInput | Equation | ExpressionInput[], variables?: string[]): Vector
Import only this function, from nerdamer/solve.
Examples
Two equations, three unknowns: z stays free.
solveeqs([x+y+z=6,x-y=2])
// → [{x => 4+(-1/2)*z, y => 2+(-1/2)*z, z => z}]Open in PlaygroundA parabola and a line meet at (-1,1) and (2,4).
solveeqs([y=x^2,y=x+2])
// → [{x => 2, y => 4}, {x => -1, y => 1}]Open in PlaygroundA circle and a line: exact irrational solutions.
solveeqs([x^2+y^2=1,y=x])
// → [{x => (1/2)*2^(1/2), y => (1/2)*2^(1/2)}, {x => (-1/2)*2^(1/2), y => (-1/2)*2^(1/2)}]Open in PlaygroundThree nonlinear equations with six isolated solutions.
solveeqs([x*y*z=6,x+y+z=6,x^2+y^2+z^2=14])
// → [{x => 1, y => 2, z => 3}, {x => 2, y => 1, z => 3}, {x => 1, y => 3, z => 2}, {x => 3, y => 1, z => 2}, {x => 2, y => 3, z => 1}, {x => 3, y => 2, z => 1}]Open in PlaygroundA mixed trigonometric and polynomial system, solved numerically: x is about ±2.68259128682539 and y about -0.196296012151.
solveeqs([cos(x)^2-y-1=0,x^2+y-7=0])
// → [{x => -2.6825912868253889607, y => -0.19629601215149626377}, {x => 2.6825912868253889607, y => -0.19629601215149626377}]Open in PlaygroundComplex coefficients and solutions.
solveeqs([2*X1-4*X2+2*i=3,-5*X1+8*X2*i-4*i*X1=2])
// → [{X1 => -6/5+(-6/5)*i, X2 => (-1/10)*(27/2+i)}]Open in PlaygroundMore equations than unknowns (overdetermined), but consistent.
solveeqs([x+y=1,2*x=6,4*z+y=6,y=-z])
// → [{x => 3, y => -2, z => 2}]Open in PlaygroundFractions are cleared first.
solveeqs([x=5,3/5=1-x/(10+y)])
// → [{x => 5, y => 5/2}]Open in PlaygroundA trigonometric equation in a system is solved numerically.
solveeqs([sin(x)=0,y=1])
// → [{x => -9.4247779607686356079, y => 1}, {x => 0, y => 1}, {x => 9.4247779607693797154, y => 1}]Open in PlaygroundGood to know
- When a nonlinear system has infinitely many solutions that aren't isolated, it throws an
UnsupportedOperationError. - Numerical solving returns the roots it finds in its search. It doesn't turn
sin(x)=0into a family of solutions; for one equation, usesolve, which does. - A comparison such as
x+y<3is an error; each item must be an equation or an expression.
Also called
solveSystem
Deprecated names
solveEquations still works, and gives the same result as solveeqs, but each call records an api.deprecatedFunction warning. Use solveeqs instead; the old name will be removed in a later major version.
