有哪些好的库可用于求解 C++ 中的非线性方程组?
在我正在编码的 C++ 应用程序中,我需要求解非线性方程组(N 个方程,N 个未知数)。
我正在求解的系统将相当小(最多 10 个方程/未知数),因此性能不会成为真正的问题。 我在网上搜索了一些非线性解算器库,但找不到看起来易于使用的东西(找到NOX和C/C++ Minpack,但这两者似乎都超出了我的需要)。
为此目的有什么易于使用的库的想法和想法吗?
In a C++ application I'm coding, I need to solve a system of non-linear equations (N equations, N unknowns).
The systems I'm solving will be rather small (up to 10 equations/unknowns), so performance is not going to be a real issue.
I've searched the web a bit for a non-linear solver library, and I couldn't get to something which looks easy to use (got to NOX and C/C++ Minpack, but both seem to be an overkill for my need).
Any thoughts and ideas of easy-to-use libraries for this purpose?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
应该清楚一件事:非线性方程的求解并不容易。这与求解线性方程不同。并不总是保证您能得到解决方案。您对初始条件和增量策略的选择可能会对您得到的解决方案产生深远的影响。
话虽如此,我不能推荐特定的库,但您应该寻找一个在其选择菜单中包含牛顿-拉夫森迭代的线性代数包。
One thing should be clear: non-linear equation solution isn't easy. It's not the same as solving linear equations. You aren't always guaranteed to get a solution. And your choice of initial condition and incrementation strategy can have a profound effect on the solution you do get.
With that said, I can't recommend a particular library, but you should be on the lookout for a linear algebra package that includes Newton-Raphson iteration in its menu of choices.
有两种选择供您选择,您可以使用 sundials 软件包,其中包含用 CI think 编写的非线性求解器。我发现它的唯一问题是您需要对其进行良好的初始估计。第二个选项是使用 NLEQ 或 NLEQ2,我认为它们更优越(用 FORTRAN 编写,但很容易链接到 C 等语言。但是我现在在定位它时遇到了一些问题。有一个很好的网站,其中列出了可能的选项位于:http://plato.asu.edu/sub/zero.html
There are two options for you, you can use the sundials packages which includes a nonlinear solver, written in C I think. The only problem I've found with it is that you need to give it good initial estimates. The second option is to use NLEQ or NLEQ2 which I think are superior (writtein in FORTRAN but easy to link to C like langages. However I have had some problems locating it just now. There is a good web site with a list of possible options at: http://plato.asu.edu/sub/zero.html
数字食谱有一个例程可以为您完成这项工作。
Numerical Recipes has a routine that will do the job for you.
这取决于方程的非线性程度。如果它们具有一些“好的”属性......最明显的是正半定矩阵或凸性,可能有专门的算法可用。我使用 IBM/ILOG CPLEX 来满足大部分线性编程需求。提供了可以拉入 C++ 应用程序的库。虽然我没有使用过他们的二次编程模块,但它确实是高马力线性和(表现良好的)非线性编程中最先进的。
It depends on how non-linear the equations are. If they possess some "nice" properties...most obvious being positive-semi-definite matrix or convexity, there may be specialized algorithms available. I use IBM/ILOG CPLEX for most of my linear programming needs. Libraries are provided that can be pulled into C++ applications. Although I have not used their quadratic programming module, it is really the state-of-the-art in high horse-power linear and (well-behaved) non-linear programming.
总是有 GSL,但其他答案中的所有评论也适用于此:
http://www.gnu.org/software/gsl/manual/html_node/MultiDimension-Root_002dFinding.html#index-nonlinear-systems -of-equations_002c-solution-of-2426
There is always GSL, but all the comments made in the other answers apply to this as well:
http://www.gnu.org/software/gsl/manual/html_node/Multidimensional-Root_002dFinding.html#index-nonlinear-systems-of-equations_002c-solution-of-2426
你看过COIN-OR吗?如果您向 OR-Exchange 提交问题可能会有所帮助。
Have you looked at COIN-OR? It might help if you submit your question to the OR-Exchange.
无论如何,它都不是免费的,但 Solver 可以在这里工作。
It's not free by any means, but Solver would work here.
Microsoft Z3 https://github.com/ Z3Prover/z3/blob/master/examples/c%2B%2B/example.cpp
还考虑 omnn::math:
https://github.com/ohhmm/openmind/ blob/master/omnn/math/test/08_System.cpp
可以说方程组是这样的:
那么你有几个选择:
替代方法是制作单个方程(参见为什么):
((x-a1)^2 + (y-b1)^2 - c1)^2 + ((x-a2)^2 + (y-b2)^2 - c2)^2 = 0
Microsoft Z3 https://github.com/Z3Prover/z3/blob/master/examples/c%2B%2B/example.cpp
also consider omnn::math:
https://github.com/ohhmm/openmind/blob/master/omnn/math/test/08_System.cpp
Lets say system of equations is like this:
Then you have couple options:
alternative way is to make single equation (see why):
((x-a1)^2 + (y-b1)^2 - c1)^2 + ((x-a2)^2 + (y-b2)^2 - c2)^2 = 0