2

有没有一个插件可以解决一个简单的方程组?

我基本上需要解决 3X3 矩阵的能力。

4

2 回答 2

3

Sylvester是一个 JavaScript 库,旨在让您使用向量和矩阵进行数学运算。

于 2011-05-17T00:30:40.087 回答
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>

于 2021-02-14T06:53:05.540 回答