One correction: this is not linear algebra, which usually means matrices of multiple equations and unknowns.
Your example, of course, is not complicated.
You need a simple expression grammar and parser. Divide the equation into an abstract syntax tree and swipe the tree to evaluate it.
If you write Java, it may look like this . Another example is symja . Perhaps you will have enough inspiration so that you can come up with your own for C ++.
You can also look at Mathematica and Wolfram Alpha. Stephen Wolfram is one of the world's best mathematicians and computer scientists. He got a lot of things that you could use in your best interests and not write yourself.
You will need to determine what you mean by โdecisionโ and what you expect to return.
There are symbolic solutions and numerical solutions. What do you have in mind? Both are equally important, but they are different. You will use different methods depending on your answer.
Another point: there are many methods for "solving" equations, which largely depend on the type of equation. If you give me something like f(x) = 0 , I am thinking of root search algorithms such as Newton's method. If you give me an ordinary differential equation, I can try the substitution method or numerical integration using Runge-Kutta. If you give me a partial differential equation, I can apply finite difference methods, finite elements, or boundary elements. (Do not start me with elliptical, parabolic and hyperbolic PDEs.)
The fact is that your question is very general, and the answer largely depends on what you are trying to do. More details may help.
source share