algebra.js icon indicating copy to clipboard operation
algebra.js copied to clipboard

Solver can't solve to fractions with variables.

Open sjorsvanheuveln opened this issue 7 years ago • 1 comments

The solver can't solve to fractions with variables. For example the speed formula: s = a/t. So the solver can solve for 'a' -> a = st, but not for 't' -> undefined. Probably because Fraction can't handle variables in the numerator or denominator. This is a serious issue.

    let expr = new Expression('s');
    expr = expr.multiply('t');

    const eq = new Equation(expr, new Expression('a'));
    const aAnswer = eq.solveFor('a');
    const tAnswer = eq.solveFor('t');

    console.log(`a = ${aAnswer}`); // this works: a = st
    console.log(`t = ${tAnswer}`); // this fails: t = undefined

sjorsvanheuveln avatar Mar 29 '18 11:03 sjorsvanheuveln

I agree, this is a large problem. It prevents many simple things from being done. For example, simply doing new algebra.Expression("a").divide("b") causes an Uncaught TypeError: Invalid Argument (b): Divisor must be of type Fraction or Integer.

LukeBorowy avatar Jun 28 '18 21:06 LukeBorowy