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$ Dec 8, 2018 at 2:25
  • $\begingroup$ My general method is the google search: google.se/search?q=5+btu+in+joule $\endgroup$
    – user137289
    Dec 8, 2018 at 9:12

2 Answers 2


If I were writing my own python program to handle this question then I would probably decide to treat physical dimensions using vectors (i.e. one dimensional arrays). The elements of the array or vector represent the basic physical quantities such as mass, length, time, electric charge, etc. Then you have two types of conversion. On the one hand there is the definition of things like energy $(M L^2/T^2$) and power (energy $/ T$); on the other there is the conversion of units. These two concepts are closely related.

To express derived quantities in terms of basic ones, one could for example say that if mass is represented by (1,0,0,0,...) and length is (0,1,0,0,...) and time is (0,0,1,0,0,...) then speed is (0,1,-1,0,...) and energy is (1,2,-2,0,0,....); etc.

Finally, to convert units you need a list of definitions such as how many metres is one mile, etc. All you need to list is the conversion of every BASIC unit to SI units, then your program can do the rest. To do the job in full would amount to a programming project so would take a while. But to write the code just for a few conversions would be pretty quick. I guess it must have been done already by many people, but I haven't seen a really thorough and well-presented example (there are poor ones you can find on many web sites).


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$ Dec 8, 2018 at 1:42
  • 1
    $\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, 2018 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$ Dec 8, 2018 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, 2018 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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