Equation Solvers for linear mathematical equations

2019-04-10 22:10发布

问题:

I need to solve a few mathematical equations in my application. Here's a typical example of such an equation:

a + b * c - d / e = a

Additional rules:

  • b % 10 = 0
  • b >= 0
  • b <= 100
  • Each number must be integer
  • ...

I would like to get the possible solution sets for a, b, c, d and e.

Are there any libraries out there, either open source or commercial, which I can use to solve such an equation? If yes, what kind of result do they provide?

回答1:

Solving linear systems can generally be solved using linear programming. I'd recommend taking a look at Boost uBLAS for starters - it has a simple triangular solver. Then you might checkout libraries targeting more domain specific approaches, perhaps QSopt.



回答2:

You're venturing into the world of numerical analysis, and here be dragons. Seemingly small differences in specification can make a huge difference in what is the right approach.

I hesitate to make specific suggestions without a fairly precise description of the problem domain. It sounds superficiall like you are solving constrained linear problems that are simple enough that there are a lot of ways to do it but "..." could be a problem.

A good resource for general solvers etc. would be GAMS. Much of the software there may be a bit heavy weight for what you are asking.



回答3:

You want a computer algebra system.

See https://stackoverflow.com/questions/160911/symbolic-math-lib, the answers to which are mostly as relevant to c++ as to c.



回答4:

I know it is not your real question, but you can simplify the given equation to:

d = b * c * e with e != 0



回答5:

Pretty sure Numerical Recipes will have something



回答6:

You're looking for a computer algebra system, and that's not a trivial thing.

Lot's of them are available, though, try this list at Wikipedia:

http://en.wikipedia.org/wiki/Comparison_of_computer_algebra_systems

-Adam



回答7:

This looks like linear programming. Does this list help?



回答8:

In addition to the other posts. Your constraint sets make this reminiscent of an integer programming problem, so you might want to check that kind of thing out as well. Perhaps your problem can be (re-)stated as one.

You must know, however that the integer programming problems tends to be one of the harder computational problems so you might end up using many clock cycles to crack it.



回答9:

Looking only at the "additional rules" part it does look like linear programming, in which case LINDO or a similar program implementing the simplex algorithm should be fine.

However, if the first equation is really typical it shows yours is NOT a linear algebra problem - no 2 variables multiplying or dividing each other should appear on a linear equation!

So I'd say you definitely need either a computer algebra system or solve the problem using a genetic algorithm.

Since you have restrictions similar to those found in linear programming though you're not quite there, if you just want a solution to your specific problem I'd say pick up any of the libraries mentioned at the end of Wikipedia's article on genetic algorithms and develop an app to give you the result. If you want a more generalist approach, then you've got to simulate algebraic manipulations on your computer, no other way around.



回答10:

The TI-89 Calculator has a 'solver' application. It was built to solve problems like the one in your example. I know its not a library. But there are several TI-89 emulators out there.