首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用javascript求解多项式方程

用javascript求解多项式方程
EN

Stack Overflow用户
提问于 2017-03-16 05:26:03
回答 3查看 4.5K关注 0票数 1

我有一个多项式方程,需要通过编程来求解。方程如下所示。

代码语言:javascript
复制
x/207000 + (x/1349)^(1/0.282) = (260)^2/(207000*x)

我需要求解x,我使用javascript来解决这个问题。javascript中有没有可以解决数学方程的库?

EN

回答 3

Stack Overflow用户

发布于 2019-08-13 22:46:19

JavaScript中的一些计算机代数系统可以求解多项式方程组。使用Algebrite,您可以解决如下方程:

roots(x^2 + 2x = 4)

这个方程的根是[-1-5^(1/2),-1+5^(1/2)]

也可以使用Nerdamer求解多项式方程组。它的文档包括以下示例:

代码语言:javascript
复制
var sol = nerdamer.solveEquations('x^3+8=x^2+6','x');
console.log(sol.toString());
//1+i,-i+1,-1
票数 3
EN

Stack Overflow用户

发布于 2021-02-12 15:29:13

有JavaScript求解器可以在数值上解决你的问题。我所知道的非线性求解器是Ceres.js。这里有一个根据你的问题改编的例子。我们要做的第一件事是重新排列成F(x)=0的形式。

x0 = 184.99976046503917

代码语言:javascript
复制
<!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>

票数 1
EN

Stack Overflow用户

发布于 2017-03-16 05:28:43

试用math.js

http://mathjs.org/

它允许您以更干净的外观来执行数学函数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42820969

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档