基于代数方程库Algebra.js解二元一次方程功能示例
本文实例讲述了基于代数方程库Algebra.js解二元一次方程功能。分享给大家供大家参考,具体如下:
假设二元一次方程如下:
x+y=11 x-y=5
解方程如下:
测试algebra函数库(解两元一次方程) varFraction=algebra.Fraction; varExpression=algebra.Expression; varEquation=algebra.Equation; //======================================= varx1=algebra.parse("x+y=11"); varanswer1=x1.solveFor("y"); //console.log("y="+answer1.toString()); varx2=algebra.parse("x-y=5"); varanswer2=x2.solveFor("y"); //console.log("y="+answer2.toString()); //================================================= //解出X值 vareq=newEquation(answer1,answer2); console.log("x表达式:"+eq.toString()); varanswerX=eq.solveFor("x"); console.log("解出X的值为:"+answerX.toString()); //================================================= //解出Y值(把x的值代入x1或x2) eq=x1.eval({ x:answerX }); console.log("y表达式:"+eq.toString()); varanswerY=eq.solveFor("y"); console.log("解出Y的值为:"+answerY.toString());