Module xxcalc::linear_solver
[−]
[src]
Defines a LinearSolver
which extends a PolynomialCalculator
with
ability of solving single linear equation.
It supports the very same operations and functions as the
PolynomialCalculator
, however a new operator =
is defined which
solves a linear equation.
One can use LinearSolverParser
, LinearSolverEvaluator
or functions
module in their own implementations, so there is no need of reimplementing
this functionality.
Examples
A LinearSolver
provides an easy way to integrate a solver and calculator into
your project. It simply takes a string expression and returns evaluated value,
however if you need high-efficiency solution you should consider using
LinearSolverParser
and LinearSolverEvaluator
directly.
use xxcalc::linear_solver::LinearSolver; use xxcalc::calculator::Calculator; use xxcalc::polynomial::Polynomial; assert_eq!(LinearSolver.process("2 * x + 0.5 = 1"), Ok(Polynomial::constant(0.25))); assert_eq!(LinearSolver.process("2x + 1 = 2(1-x)"), Ok(Polynomial::constant(0.25))); assert_eq!(LinearSolver.process("x^2-x^2+x=2"), Ok(Polynomial::constant(2.0))); assert_eq!(LinearSolver.process("1-x=x"), Ok(Polynomial::constant(0.5)));Run
Modules
functions |
Implementation of solving operator handler. |
Structs
LinearSolver |
|
LinearSolverEvaluator |
Extends |
LinearSolverParser |
Extends |
Enums
SolvingError |
An error that occurs during linear solving. |