nicolewhite/algebra.js

Best approch for solving an equation

sonnyk22 opened this issue · 6 comments

Great library!

What is the best way to solve for the equation below?

Solving for x;
2(x-2)(x+3)/5+3/4(x-2)+2x-3/2x^2+2=3(x-2)+(2x-3)(2x+2)-4

Would the below statement work? Using the algebra.parse() function will surely be very beneficial for everyone out there, instead of manually constructing the equation below using the provided Expression()/subtract()/divide()/add() functions.

 var eq = algebra.parse("2(x-2)(x+3)/5+3/4(x-2)+2x-3/2x^2+2=3(x-2)+(2x-3)(2x+2)-4");

Is there a demo site available at this time for this library?

Thanks

The library is loaded at http://algebra.js.org/.
Open your developer console at the site and type your equation in it.

The Equation you asked for:

var eq = algebra.parse("2(x-2)(x+3)/5+3/4(x-2)+2x-3/2x^2+2=3(x-2)+(2x-3)(2x+2)-4");
eq.solveFor("x");

returned

[59.790070442233, -47.21257044223301]

Thanks for getting back to me on this.

When I tried the Algebra.Parse() function on a few equations (basic to complex), it worked great, but unfortunately I think the returned result of [59.790070442233, -47.21257044223301] for the equation below (in my original post) may be incorrect.

var eq = algebra.parse("2(x-2)(x+3)/5+3/4(x-2)+2x-3/2x^2+2=3(x-2)+(2x-3)(2x+2)-4");
eq.solveFor("x");
AlgebraJS result: [59.790070442233, -47.21257044223301]

I believe the correct result is [-1.46526, 1.88683]. I used a few websites to make sure of this result, such as http://www.homeschoolmath.net/worksheets/equation_calculator.php.

Is there something else that I need to provide to the AlgebraJS to get this correct result?

I think you've found a couple bugs here; you can see them above.

I tested your input again after I fixed issue #40 and now the result is
[ 1.8868320186747458, -1.4652633912237656 ]

Awesome! Thank you

These fixes have been pushed under v0.2.4, which I just published to npm and the script available at http://algebra.js.org is up to date as well.