如何使用algebra.js求解代数方程

时间:2016-08-02 08:35:03

标签: javascript html algebra



<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/algebra.css">

<script src="js/algebra-0.2.5.min.js"></script>


<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/katex.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/katex.min.js"></script>


</head>
<body>

<div id="myEquation"></div>
<div id="mySolution"></div>

<script>
window.onload=function(){



var expr1 = new Expression("x");
expr1 = expr1.add(2);
expr1 = expr1.multiply(4);

var expr2 = new Expression("x");
expr2 = expr2.multiply("y");
expr2 = expr2.multiply(new Fraction(1, 3));
expr2 = expr2.add(4);

var expr3 = expr1.multiply(expr2);

console.log("(" + expr1.toString() + ")(" + expr2.toString() + ") = " + expr3.toString());

}
</script>



</body>
</html>
&#13;
&#13;
&#13;

我有一些代码没有得到任何数据什么是错误我的代码请更正它。如何解决代数方程例如10x2 + 10y-90 = 100请帮助我。在该代码中如何使用algebra.js。

1 个答案:

答案 0 :(得分:0)

您错过了变量定义,将脚本更改为

var Fraction = algebra.Fraction;
var Expression = algebra.Expression;
var Equation = algebra.Equation;

var expr1 = new Expression("x");
expr1 = expr1.add(2);
expr1 = expr1.multiply(4);

var expr2 = new Expression("x");
expr2 = expr2.multiply("y");
expr2 = expr2.multiply(new Fraction(1, 3));
expr2 = expr2.add(4);

var expr3 = expr1.multiply(expr2);

console.log("(" + expr1.toString() + ")(" + expr2.toString() + ") = " + expr3.toString());

这些是错过的陈述

var Fraction = algebra.Fraction;
var Expression = algebra.Expression;
var Equation = algebra.Equation;

Here a working pen