Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

algebra.js 0.2.0

Compare
Choose a tag to compare
@nicolewhite nicolewhite released this 20 Aug 21:26
· 93 commits to master since this release

Bug Fixes

Single-variable equations with an infinite number of solutions were returning undefined when solved. They now return Fraction(1, 1).

var exp = new Expression("x").add(2); // x + 2

var eq = new Equation(exp, exp); // x + 2 = x + 2

var ans = eq.solveFor("x"); // 1

New Features

Parser

You can now build expressions and equations from strings.

var exp = algebra.parse("x^2 + 4 * x + 4");

var eq = algebra.parse("x^2 + 4 * x + 4 = 0");

Expression Simplification

You can now pass a simplify argument to all Expression operations.

var exp = new Expression("x").add(2); // x + 2

exp = exp.multiply(5, false); // 5x + 5 * 2

exp = exp.simplify(); // 5x + 10

exp = exp.add(5, false); // 5x + 10 + 5

exp = exp.divide(5, false); // 5/5x + 10/5 + 5/5

exp = exp.simplify(); // x + 3

exp = exp.pow(2, false); // xx + 3x + 3x + 3 * 3

exp = exp.eval({x: 2}, false); // 2 * 2 + 3 * 2 + 3 * 2 + 3 * 3

Summation

A summation method has been added to the Expression class. It allows you to sum over a range for a specific variable.

sum

var exp = new Expression("x").add("y").add(3); // x + y + 3

var sum = Expression.summation("x", 3, 6); // 4y + 30