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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With