我有一个多项式方程,需要通过编程来求解。方程如下所示。
x/207000 + (x/1349)^(1/0.282) = (260)^2/(207000*x)我需要求解x,我使用javascript来解决这个问题。javascript中有没有可以解决数学方程的库?
发布于 2019-08-13 22:46:19
JavaScript中的一些计算机代数系统可以求解多项式方程组。使用Algebrite,您可以解决如下方程:
roots(x^2 + 2x = 4)
这个方程的根是[-1-5^(1/2),-1+5^(1/2)]。
也可以使用Nerdamer求解多项式方程组。它的文档包括以下示例:
var sol = nerdamer.solveEquations('x^3+8=x^2+6','x');
console.log(sol.toString());
//1+i,-i+1,-1发布于 2021-02-12 15:29:13
有JavaScript求解器可以在数值上解决你的问题。我所知道的非线性求解器是Ceres.js。这里有一个根据你的问题改编的例子。我们要做的第一件事是重新排列成F(x)=0的形式。
x0 = 184.99976046503917
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<h2>User Function</h2>
<p>This is an example of the solution of a user supplied function using Ceres.js</p>
<textarea id="demo" rows="40" cols="170">
</textarea>
<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]/207000 + Math.pow((x[0]/1349),(1/0.282)) - Math.pow((260),2)/(207000*x[0]);
}
let solver = new Ceres()
solver.add_function(fn1) //Add the first equation to the solver.
solver.promise.then(function(result) {
var x_guess = [1] //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>
发布于 2017-03-16 05:28:43
试用math.js
http://mathjs.org/
它允许您以更干净的外观来执行数学函数。
https://stackoverflow.com/questions/42820969
复制相似问题