Function xxcalc::linear_solver::functions::solver [] [src]

pub fn solver(args: Vec<Polynomial>) -> Result<PolynomialEvaluationError>

Solves a linear equation for a value of x (requires two arguments).

Solving is done by moving x coefficients to LHS and constants to RHS, than after a scaling (division by x coefficient), a value of x is obtained.

Errors

The solver detects multiple situations where solving is not possible.

A NonLinear error is returned when provided equation is not linear (has a polynomial of degree greater than one).

assert_eq!(LinearSolver.process("x^2=1").unwrap_err(), CalculationError::EvaluationError(EvaluationError::SolvingError(SolvingError::NonLinear)));Run

A NoSymbol error is returned when provided expression is not really an equation to solve, as there is no symbol x used.

assert_eq!(LinearSolver.process("0=0").unwrap_err(), CalculationError::EvaluationError(EvaluationError::SolvingError(SolvingError::NoSymbol)));Run

A Tautology error is returned when provided equation is solvable for any value of x.

assert_eq!(LinearSolver.process("x=x").unwrap_err(), CalculationError::EvaluationError(EvaluationError::SolvingError(SolvingError::Tautology)));Run

A NonSolvable error is returned when provided equation has no solutions.

assert_eq!(LinearSolver.process("x=x+1").unwrap_err(), CalculationError::EvaluationError(EvaluationError::SolvingError(SolvingError::NonSolvable)));Run