Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Agreed, it's super useful to write out all the units and check that they cancel out properly.

I usually write out the Witt I want to convert, complete with units, and successively multiply by dimensionless conversion factors which equal 1.

That is to convert 45 MPG to "km/l" I'd write out:

45 (mile / UK gallon) * (1 UK gallon / 4.55 l) * (1.6 km / 1 mile)

The expression (1.6 km / 1 mile) is dimensionless and equal to 1 (it's a length divided by an equal length).

Cancelling the units gives (45 / 4.55 * 1.6) km/l



I taught an hour-long class at work where I'd prepped an example to warm the group up, which involved converting the sales material for a US car that got 26 mpg to a Canadian market using liters per 100 km. 26 mpg is carefully chosen because between 1/3 and 2/3 (usually on the lower end) would get it right (~9 liters per 100km) and the others would often come up with around 11 (km per liter).

I could then ask "who got a figure around 9?" and "who got a figure around 11?" and both groups would raise their hand feeling pretty confident they'd gotten it right. I'd then introduce and walk them through dimensional analysis and finish with an example that was more complex and error-prone, but was pretty straightforward if you just applied DA.

(The main point of the class was "use correct units" rather than "learn dimensional analysis".)


The great thing about that conversion is that due to the reciprocal relationship the same conversion formula works both ways, so you don't have the risk of converting the wrong way.


I use 'ruby-units' with ruby's 'irb' in order to do complex unit calculations. It's an excellent library and with some helpers one can write:

    (U('45 mi') / U('1.20095 gal')) >> 'km/l'
It doesn't come with an imperial gallon, but it could be added. It's also fun to do stuff like:

    (U('3.99e33 ergs/s') / (4 * Math::PI * U('1 AU')**2)) >> 'W/m^2'
To get the potential available solar energy output at earth's average orbital distance from the sun usefully expressed as Watts per Square Meter.

Anyways, what I really got from unit analysis was a more useful and fundamental understanding of electronics. Getting an intuition for how Tesla's relate to Weber's relate to Volts and Ohms and how the Coloumb relates to the Ampere and Siemen and how they all combine into Henry's and Farad's both to ultimately lead you right into Joule's and Watt's. I really wish I was taught the material that way.


Similar library for Julia is Unitful.jl (https://github.com/PainterQubits/Unitful.jl).


Exactly. I consider it much like "types" in programming languages: middling to weak "formal verification". In the case of most calculations I've ever carried out substantially 'by hand' in physics / chemistry / etc., it still made / makes a substantial difference in error rate.

Without propagating dimensions, my error rate can be a real issue. I wouldn't trust the final number on a full, say, roughly "letter-sized" (US 'wonderland' system) page. By propagating, I might trust the result 75 or 80% of the time...

(I do rather doubt I could have been an even average NASA "computer" given the opportunity to do a great deal more of these kinds of calculations than I have had to... my mind is much better at generating random numbers and nonsense than doing anything 'mechanical'. AFAIK, NASA had no call for such skills in the "age of human computers".) :)


It is a type in the mathematical sense too, so it makes sense to treat it like it




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: