C
Chris Smith
Dan said:I am looking for an algorithm to solve an equation for any particular
variable. For example, if I have the equation y = w * h + l (actually
I have y = w h * l + because I'm using postfix notation), I need an
algorithm that can solve the equation for any of w, h, l.
I only support the four basic operators in my equations ( + - * / )
and do not support functions. The way I store the equation is in a
container; each item in the container is either a variable name or an
Integer representing the operation, where + is 2, - is 3, * is 4 and /
is 5.
Can you limit the order of the equation with respect to the variable for
which you're solving? If not, I'm afraid you'll have a tough time
finding a deterministic solution.
If you can (and the order is 1), then this isn't too difficult. You
would divide each side of the equation into terms (pieces that are all
multiplied together), and get all the terms *with* the variable on one
side, and all the terms without it on the other. Then you'd remove the
variable and divide the side that didn't have it by the side that did,
using polynomial division.
If you need to solve quadratic and other more complex equations, then
you've got harder work.
Is that what you wanted?
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation