JavaScript方程求解器库 [英] JavaScript equation solver library

查看:75
本文介绍了JavaScript方程求解器库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个JavaScript库或函数可以解决变量的等式?

Is there a JavaScript library or function that will solve equations for variables?

例如 9 = 3 + x 并解决x。但它也应该解决更高级的方程,包括正弦,余弦和正切。

Such as 9 = 3 + x and solve for x. But it should also solve more advanced equations that include sine, cosine, and tangent.

推荐答案

你可以近似通过做excel调用目标寻求的解决方案 - 测试 x 的值,直到等式的两边大致匹配。您可以通过=符号分割等式,用值替换 x 的每个出现, eval 双方,并确定差异是否低于某个阈值。虽然相对简单,但这种方法存在缺陷(除了它是近似的事实),例如算法可能认为双方正在收敛,而实际上它只是一个局部最小值/最大值并且会在之后发散。差异刚好低于你的门槛。您还需要测试多个起点以解决具有多个解决方案的方程式。

You can approximate the solution by doing what excel calls "Goal Seek" - testing values for x until both sides of the equation approximately match. You can do this by splitting the equation by the "=" sign, replacing each occurence of x with a value, evaling both sides, and determining if the difference falls below a certain threshold. While relatively simple, there are flaws to this method though (other than the fact that it is an approximation), for example the algorithm may think the two sides are converging when in fact it is just a local min/max and will diverge after the difference falls just below your threshold. You'll also need to test multiple start points to solve equations with more than one solution.

对于实际求解等式的程序人类会(通过重新排列等式的两边并应用反函数,导数/积分等等)更加复杂,并且不知何故感觉完全专有;)

For a program to actually solve an equation as a human would (by rearranging the two sides of the equation and applying inverse functions, derivatives/integrals and whatnot) is far more complex, and somehow feels entirely proprietary ;)

这篇关于JavaScript方程求解器库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆