Skip to content

Instantly share code, notes, and snippets.

@lorenzoongithub
Created August 18, 2015 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lorenzoongithub/c9b38a90a45e898a3ca1 to your computer and use it in GitHub Desktop.
Save lorenzoongithub/c9b38a90a45e898a3ca1 to your computer and use it in GitHub Desktop.
//
// algebraic equations
// in javascript
// http://algebra.js.org/
//
load('http://algebra.js.org/javascripts/algebra.min.js');
var Expression = algebra.Expression;
var Equation = algebra.Equation;
var Fraction = algebra.Fraction;
expr = new Expression("x");
expr = expr.subtract(3);
expr = expr.add("x");
if (expr.toString() != '2x - 3') throw '';
eq = new Equation(expr, 4);
if (eq.toString() != '2x - 3 = 4') throw '';
var x = eq.solveFor("x");
if (x.toString() != '7/2') throw '';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment