3
$\begingroup$

I took Algebra and Geometry in high school, never thought I'd use them, then became a programmer. I guess I was wrong.

To date, I have the hardest time taking equations and "flipping them," ie: rewriting an equation to find the reverse. For the current problem I'm dealing with, I have a formula that converts floats to pounds using a given ratio:

pounds = float * (1.0 / ratio) 

How do I flip this to take pounds and ratio and solve for float? What's the theory and logic behind this? I'd like to understand how it works so I can do it on my own. Can anyone walk me through how this would be done so I can understand how to change my formulae to solve things backwards?

float = ? 
  • 1
    This line of code is equivalent to `pounds = float / ratio` which, if you multiply both sides by `ratio`, gives you `float = pounds * ratio`.2012-02-07
  • 0
    It's not exactly equivalent, as my `ratio` is usually less than one.2012-02-07
  • 2
    It's still equivalent (multiplying by $1/x$ gives the same result as dividing by $x$).2012-02-07
  • 0
    Just thought I should edit to add that in some programming languages it won't be equivalent (though the two expressions are, mathematically, identical). For example, Python interprets `/` as integer division if both operands are integers, but as floating point division if one or more of the operands is a float. So the expression `3 / 2` evaluates to `1`, but the expression `3 * (1.0 / 2)` evaluates to `1.5`. This is why we don't use dynamic programming languages for serious numerical applications!2012-02-07
  • 1
    Python 3 always uses floating point operations, unless otherwise noted ;)2012-02-08
  • 0
    @NaftuliTzviKay Your question is probably appropriate for the nearly-in-beta-SE http://area51.stackexchange.com/proposals/64216/mathematics-learning-studying-and-education. Check out the proposal and commit to it if you're interested. Then we can get it off the ground and get the site in beta!2014-03-03

1 Answers 1