I'm not exactly sure where the best place to put this, as it's more of a general question about dimensional analysis.

I decided I was tired of having to convert units all of the time, and was not satisfied with the available python libraries for conversion of units. I decided to make my own, and it was simple enough to get write a rough outline of a unit conversion program using this article. However, this only works for units that are scalar multiples of others. Relative units such as Celsius do not work.

I switched to implementing conversions as graph of units to traverse, converting at each step of the way. I can convert $m / s $ to $ft / hr$ by doing repeatedly replacements. The problem comes that sometimes there is no substation. To make the conversion, $$\frac{kg*m^2}{s}=1000\frac{kg*L}{m*s},$$ you have to first multiply both sides by another unit before there is a valid conversion to be made.

Is the only possiblity to have quotient units multiply the top and bottom by every single unit? This seems horribly inefficient. Are there any other similar problems I'm missing?

  • $\begingroup$ Do you intend to write your own code, or are you willing to use a small program that already does conversions? $\endgroup$ – David White Dec 8 '18 at 2:25
  • $\begingroup$ My general method is the google search: google.se/search?q=5+btu+in+joule $\endgroup$ – Pieter Dec 8 '18 at 9:12

Just convert everything to a fixed set of base units (SI units would be a good choice). So you would set $\mathrm{L} = 10^{-3} \mathrm{m}^{3}$, $\mathrm{ft} = 0.304 \mathrm{m}$ etc. Once you've expressed the left and right hand side as a scalar times powers of your base units you just have to divide the scalars.

  • $\begingroup$ That was the simple way I stated with. But there's no way to include a relative unit like Celsius and those conversions still need to be done manually. I might want to use the ideal gas law to find a volume but give the temperature in Celsius. Considering this is one of the most common conversions to make it would be quite nice if this was just integrated with the conversion system. $\endgroup$ – TheLoneMilkMan Dec 8 '18 at 1:42
  • $\begingroup$ @TheLoneMilkMan The problem is that Celsius is not really a unit: $5 K = 10^\circ C - 5^\circ \neq 5^\circ C = 278.15 K$. You should always convert any temperature to Kelvin (and temperature Differences always have to be expressed in Kelvin anyway) before doing arithmetic. BTW you can do the same for Fahrenheit just convert $^\circ F$ to the Rankine scale. $\endgroup$ – 0x539 Dec 8 '18 at 1:49
  • 3
    $\begingroup$ @0x539 The degree Celsius is an SI derived unit (from degrees Kelvin) and I'm honestly baffled why the OP has such a problem converting between these common temperature scales. The formulas are well known. The OP seems locked into the idea that conversions should be simple multiplication only, which is wrong. $\endgroup$ – StephenG Dec 8 '18 at 3:33
  • 2
    $\begingroup$ To repeat @0x539: Temperature can be either a point or a distance. One of these is wrong: "Keep the incubator at 20 degrees Celsius (68 degrees Fahrenheit)" and "At altitudes above 2000 m, add 20 degrees Celsius (68 degrees Fahrenheit) to the cooking temperature". $\endgroup$ – DJohnM Dec 8 '18 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.