How to convert an equation into formulas for individual variables?

How to convert an equation into formulas for individual variables? I think about math equations:

c^2 = a^2 + b^2 

I would like to have a function that could process any formula and give me the formulas of the individual variables. The above equation will create the following:

 a = (c^2 - b^2)^0.5 b = (c^2 - a^2)^0.5 c = (a^2 + b^2)^0.5 

I would also like to start with:

 a = (c^2 - b^2)^0.5 

and conclusion:

 b = (c^2 - a^2)^0.5 c = (a^2 + b^2)^0.5 

I looked at the expression trees, but it's hard for me to understand how this will work. I would like to have a .NET solution (C #, VB.NET or F #). Any ideas?

Sort of:

 public string[] GetFormulas(string equation) { ... } 

Thanks.

+4
source share
8 answers

Solving symbolic equations is a complex task and for many equations there is no closed solution. Writing your own Computer Algebra System is not trivial, but you can write a program for a simple equation.

You will need to build the expression tree of the input string and define transformation rules to manage the expression tree. To solve this problem for a variable, you can perform a search (oriented towards a good heuristic to maintain an acceptable working environment) in the space of the expression tree, which can be obtained from the original tree by several applications of the transformation rule.

+6
source

This is a non-trivial problem that you are trying to solve ... I do not think that you will be able to solve it yourself. Better to find some third-party application or library that does this. There are a number of programs that can perform the operation you are talking about, for example, Matlab and Maple. In addition, the TI-89 graphical calculator can do this. You can get the necessary algorithms from Octave , which is essentially an open source implementation of Matlab.

+4
source

Your only choice is to reinstall it using all known methods. In simple algebraic equations like you may be enough, but more complex problems will require ever more complex solutions. In short, it will not be easy.

Once you figure out how to parse text into characters, it may be quite simple to create an application that can determine what

 c^2 = a^2 + b^2 

can be replaced as

 c = (a^2 + b^2)^.5 

but what about

 cos(c) = sin(a^2/b) - b^(a/sin(b)) 

Worse, you have unsolvable integration and abstract algebra ... You will have to draw a line of complexity somewhere, otherwise you just finish creating another Maple .

+2
source

This is what you probably want to take a look at using the math library. For .NET, Math.NET seems to be the most complete option (not sure how stable it is, but it is certainly very complete). A library for performing symbolic manipulations should be able to cope with the specific problem you asked here.

Honestly, writing it from scratch should not be too difficult, but if you are not very familiar with expression trees and don’t know how to approach this task, I would recommend using the existing mathematical library, or Math.NET, or any other worthy which performs symbolic algebra.

+1
source

Working with equations in a symbolic and odd form is definitely not an easy task. I think the easiest way for you would be to just use Mathematica, Maple or the like backstage and let them do the hard work for you.

+1
source

Since c ^ 2 = a ^ 2 + b ^ 2 is not an expression in C #, you are in the wrong direction.

Forget about .NET expression trees and create your own. You need to describe the algorithms needed for these transformations and the data needed to describe the equation. You will find that what you are ending up is very different from the .NET expression tree.

0
source

In addition to what has already been said, you can take a look at numerical methods.

There are algorithms for approximating the solution (s) of the equation. Because most of them will not be so simple (or even impossible) to decide exactly.

0
source

Disgusting problem in general. For low order polynomial expressions, this is not too hard. For linear tasks, you only need a parser and a little post-processing. But even a simple expression for writing may be less trivial. For example, what will you do with

 x^5 + y^5 - xy + 1 = 0 

A solution for any of x or y in terms of other means that you must solve for the roots of a polynomial of a variable coefficient of order 5. This is generally impossible to do.

Worse, enter trigger functions or any special function in the mix and this will force you to rewrite Mathematica before you finish.

0
source

All Articles