是否有可以解决简单方程组的插件?
我基本上需要能够解决3X3矩阵。
答案 0 :(得分:3)
Sylvester是一个JavaScript库,旨在让您使用向量和矩阵进行数学运算。
答案 1 :(得分:0)
[Ceres.js]:https://github.com/Pterodactylus/Ceres.js 是另一种在 JavaScript 中数值求解多个非线性方程的工具。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="https://www.desmos.com/api/v1.4/calculator.js?apiKey=dcb31709b452b1cf9dc26972add0fda6"></script>
</head>
<body>
<h2>Quadratic Function</h2>
<p>This is an example of the solution of the quadratic function using <a href="https://github.com/Pterodactylus/Ceres.js">Ceres.js</a></p>
<div id="calculator" style="width: 600px; height: 400px;"></div>
<script>
var elt = document.getElementById('calculator');
var calculator = Desmos.GraphingCalculator(elt);
calculator.setExpression({ id: 'exp1', latex: 'x+10*y-20 = 0' });
calculator.setExpression({ id: 'exp2', latex: "\\sqrt{5}*x-y^2 = 0" });
</script>
<p>
<textarea id="demo" rows="40" cols="170">
</textarea>
</p>
<script type="module">
import {Ceres} from 'https://cdn.jsdelivr.net/gh/Pterodactylus/Ceres.js@master/Ceres-v1.5.3.js'
var fn1 = function f1(x){
return (x[0]+10*x[1]-20); //this equation is of the for f1(x) = 0
}
var fn2 = function f2(x){
return (Math.sqrt(5)*x[0]-Math.pow(x[1], 2)); //this equation is of the for f2(x) = 0
}
let solver = new Ceres()
solver.add_function(fn1) //Add the first equation to the solver.
solver.add_function(fn2) //Add the second equation to the solver.
//solver.add_callback(c1) //Add the callback to the solver.
//solver.add_lowerbound(0,1.6) //Add a lower bound to the x[0] variable
//solver.add_upperbound(1,1.7) //Add a upper bound to the x[1] variable
solver.promise.then(function(result) {
var x_guess = [1,2] //Guess the initial values of the solution.
var s = solver.solve(x_guess) //Solve the equation
var x = s.x //assign the calculated solution array to the variable x
document.getElementById("demo").value = s.report //Print solver report
solver.remove() //required to free the memory in C++
})
</script>
</body>
</html>