有哪些好的库可用于求解 C++ 中的非线性方程组?

发布于 2024-10-03 12:14:16 字数 295 浏览 5 评论 0原文

在我正在编码的 C++ 应用程序中,我需要求解非线性方程组(N 个方程,N 个未知数)。

我正在求解的系统将相当小(最多 10 个方程/未知数),因此性能不会成为真正的问题。 我在网上搜索了一些非线性解算器库,但找不到看起来易于使用的东西(找到NOXC/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

听闻余生 2024-10-10 12:14:16

应该清楚一件事:非线性方程的求解并不容易。这与求解线性方程不同。并不总是保证您能得到解决方案。您对初始条件和增量策略的选择可能会对您得到的解决方案产生深远的影响。

话虽如此,我不能推荐特定的库,但您应该寻找一个在其选择菜单中包含牛顿-拉夫森迭代的线性代数包。

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.

白色秋天 2024-10-10 12:14:16

有两种选择供您选择,您可以使用 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

陌上青苔 2024-10-10 12:14:16

数字食谱有一个例程可以为您完成这项工作。

Numerical Recipes has a routine that will do the job for you.

因为看清所以看轻 2024-10-10 12:14:16

这取决于方程的非线性程度。如果它们具有一些“好的”属性......最明显的是正半定矩阵或凸性,可能有专门的算法可用。我使用 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.

挽袖吟 2024-10-10 12:14:16

你看过COIN-OR吗?如果您向 OR-Exchange 提交问题可能会有所帮助。

Have you looked at COIN-OR? It might help if you submit your question to the OR-Exchange.

当梦初醒 2024-10-10 12:14:16

无论如何,它都不是免费的,但 Solver 可以在这里工作。

It's not free by any means, but Solver would work here.

挽手叙旧 2024-10-10 12:14:16

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
(x-a2)^2 + (y-b2)^2 = c2

那么你有几个选择:

Valuable a1, a2, b1, b2; // init with values

System sys;
Variable x,y;
sys << (x-a1)^2 + (y-b1)^2 - c1; // addin an equation as an equality to 0
sys << (x-a2)^2 + (y-b2)^2 - c2;

for(auto& solution : sys.Solve(x))
        std::cout << solution;

替代方法是制作单个方程(参见为什么):

((x-a1)^2 + (y-b1)^2 - c1)^2 + ((x-a2)^2 + (y-b2)^2 - c2)^2 = 0

Variable x,y;
Valuable a1, a2, b1, b2; // init with values
auto eq = ((x-a1)^2 + (y-b1)^2 - c1)^2 + ((x-a2)^2 + (y-b2)^2 - c2)^2;
eq.SetView(Valuable::View::Equation);  // optional: equation optimizations
// get y function:
auto fn = eq(y);

// show
std::cout << fn << std::endl;

// evaluate
auto evaluate = fn;
evaluate.eval(x, 10);
evaluate.optimize(); // calculate
// show calculated value at x=10:
std::cout << evaluate << std::endl;

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:

(x-a1)^2 + (y-b1)^2 = c1
(x-a2)^2 + (y-b2)^2 = c2

Then you have couple options:

Valuable a1, a2, b1, b2; // init with values

System sys;
Variable x,y;
sys << (x-a1)^2 + (y-b1)^2 - c1; // addin an equation as an equality to 0
sys << (x-a2)^2 + (y-b2)^2 - c2;

for(auto& solution : sys.Solve(x))
        std::cout << solution;

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

Variable x,y;
Valuable a1, a2, b1, b2; // init with values
auto eq = ((x-a1)^2 + (y-b1)^2 - c1)^2 + ((x-a2)^2 + (y-b2)^2 - c2)^2;
eq.SetView(Valuable::View::Equation);  // optional: equation optimizations
// get y function:
auto fn = eq(y);

// show
std::cout << fn << std::endl;

// evaluate
auto evaluate = fn;
evaluate.eval(x, 10);
evaluate.optimize(); // calculate
// show calculated value at x=10:
std::cout << evaluate << std::endl;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文