我有一个多项式方程,需要以编程方式求解。等式如下。
x/207000 + (x/1349)^(1/0.282) = (260)^2/(207000*x)
我需要解决x。我正在使用javascript。 javascript中有没有可以解决数学方程式的库?
答案 0 :(得分:1)
答案 1 :(得分:1)
有一些 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>
答案 2 :(得分:0)