Class EquationSystemSolver
SOLVE equations, and fits a group's
(the engine side of SOLVE and SOLVE … PER).
The unknowns of a row are the participating columns that are NULL in it.
A row is solved when there are exactly as many unknowns as equations, by the
cheapest strategy that applies:
- a single equation whose unknown appears once is inverted by rearranging it
(
EquationSolver); - equations linear in the unknowns — no product of two terms that both hold an
unknown, no unknown in a divisor — are set up by evaluating each
left − rightwith its gradient (Dual) and solved by elimination (LinearSystems); a singular system leaves the row unchanged; - anything else is solved iteratively (
Newton), which leaves the row unchanged when the equations do not determine the unknowns and raises when they have no solution or the search does not converge.
Results are rounded to ten fractional digits, RoundingMode.HALF_UP,
trailing zeros stripped — the precision of ÷.
The equations are expected in their planned form, with every user-defined function expanded. Instances are immutable and thread-safe.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe round cap whenMAX … ROUNDSis not given.static final BigDecimalThe convergence tolerance whenWITHINis not given: 10⁻¹⁰. -
Constructor Summary
ConstructorsConstructorDescriptionA solver with the default tolerance and round cap, inverting single equations with a defaultOperandEvaluator.EquationSystemSolver(OperandEvaluator evaluator, BigDecimal tolerance, int maxRounds) A solver with the given iteration limits. -
Method Summary
Modifier and TypeMethodDescriptionFits the equations' unknowns across a group of rows (the engine side ofSOLVE … PER), returning every row of the group with the fitted values written in, or the group unchanged when it cannot be posed.solve(List<SolveEquation> equations, Row row) Returnsrowwith its unknowns filled, or unchanged when it cannot be posed.
-
Field Details
-
DEFAULT_TOLERANCE
The convergence tolerance whenWITHINis not given: 10⁻¹⁰. -
DEFAULT_MAX_ROUNDS
public static final int DEFAULT_MAX_ROUNDSThe round cap whenMAX … ROUNDSis not given.- See Also:
-
-
Constructor Details
-
EquationSystemSolver
public EquationSystemSolver()A solver with the default tolerance and round cap, inverting single equations with a defaultOperandEvaluator. -
EquationSystemSolver
A solver with the given iteration limits.- Parameters:
evaluator- the evaluator a single inverted equation's known side is read with; must not be nulltolerance- the largest step an iteration may still take and be converged; positivemaxRounds- the iteration's round cap; at least 1
-
-
Method Details
-
solve
Returnsrowwith its unknowns filled, or unchanged when it cannot be posed.- Parameters:
equations- the equations, every function expanded; must not be nullrow- the row to complete; must not be null- Returns:
- the completed row, or
rowitself - Throws:
EvaluationException- on a non-numeric known value, a division by zero among the known terms, or an iteration that does not converge
-
fit
Fits the equations' unknowns across a group of rows (the engine side ofSOLVE … PER), returning every row of the group with the fitted values written in, or the group unchanged when it cannot be posed.The unknowns are the participating columns that are
NULLin every row of the group; the observations are the rows in which every other participating column is present, each contributing one residualleft − rightper equation. The fit minimises the sum of the squared residuals and needs at least as many residuals as unknowns. Equations linear in the unknowns are fitted directly, by the normal equations; anything else iteratively (Newton), which raises when it does not converge. A fit that does not determine the unknowns — a singular system — leaves the group unchanged. With as many residuals as unknowns the fit is the exact solve.- Parameters:
equations- the equations, every function expanded; must not be nullgroup- the rows of one group, all of one schema; must not be nullsubject- names the group in a diagnostic, e.g.material=steel- Returns:
- the group's rows, in order, completed or unchanged
- Throws:
EvaluationException- on a non-numeric known value, a division by zero among the known terms, or an iteration that does not converge
-