How to convert an equation into formulas for individual variables? I am thinking about a math equations like:

```
c^2 = a^2 + b^2
```

I would like to have a function that could process any formula, and give me the individual variable formulas. The above equation would produce 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 output:

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

I have looked at expression trees, but I am having trouble visualizing how this will work. I would like a .NET (C#, VB.NET, or F#) solution. Any ideas?

Something like:

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

Thanks.

Symbolic equation solving is a complex problem and there is no closed solution for many equations. Writing your own Computer Algebra System is none trivial, but you may be able to write a program for simple equation.

You will have to build a expression tree of the input string and define transformation rules for manipulating the expression tree. To solve for a variable you might then perform a search (guided by good heuristics to keep the runtime acceptable) on the space of expression tree that can be derived from the orginal tree by multiple aplications of transformation rules.

This is a non-trivial problem you're trying to solve... I don't think you'll have much luck trying to solve it on your own. Better to find some kind of third-party app or library that does it. There are a number of programs that can do the operation you're talking about, such as Matlab and Maple. Also, a TI-89 graphing calculator can do it. You may be able to get the algorithms you need from Octave, which is essentially an open-source implementation of Matlab.

Licensed under: CC-BY-SA with attribution

Not affiliated with Stack Overflow