Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: Algorithm to solve equation for variable

Thread Tools

Re: Algorithm to solve equation for variable

Chris Smith
Posts: n/a
Dan wrote:
> 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?

The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Reply With Quote
Dale King
Posts: n/a
"Dan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ...
> I obviously had not thought hard enough about what I wanted! I guess
> in my mind I had limited the problem so that each variable appeared
> only once in the equation. Sorry for the half-baked question.

I'm not sure your question is really half-baked, perhaps you just did not
explain it very well. Perhaps if you gave an example of what you mean by
solving the equation.

Your original problem statement gave one equation with 4 variables. There
are typically an infinite number of combination of the four variables for
which the equation will hold.

Perhaps what you meant was that given all but one of the variables solve for
the remaining one. That is doable, but there probably isn't much off the
shelf solvers for that except something like Maple.
Dale King

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to solve complex equation? Usama Khan Python 6 01-02-2013 03:55 AM
How to solve a three-element equation set? purple Python 2 03-19-2008 07:43 PM
Key generation algorithm and Cipher algorithm Ahmed Moustafa Java 0 11-15-2003 06:35 AM
Re: Algorithm to solve equation for variable pete kirkham Java 0 06-27-2003 10:39 PM
Re: Algorithm to solve equation for variable David Zimmerman Java 0 06-27-2003 08:37 PM