What good libraries are there for solving a system of non-linear equations in C++?

后端 未结 8 1484
情书的邮戳
情书的邮戳 2021-02-06 01:12

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 sm

相关标签:
8条回答
  • 2021-02-06 01:54

    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.

    0 讨论(0)
  • 2021-02-06 01:55

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

    0 讨论(0)
  • 2021-02-06 01:57

    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.

    0 讨论(0)
  • 2021-02-06 02:00

    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;
    
    0 讨论(0)
  • 2021-02-06 02:03

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

    0 讨论(0)
  • 2021-02-06 02:04

    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

    0 讨论(0)
提交回复
热议问题