Hacker News new | past | comments | ask | show | jobs | submit login
What Is Dimensional Analysis? (cgad.ski)
104 points by cgadski on Sept 14, 2023 | hide | past | favorite | 78 comments



Shout out to https://instacalc.com/ . It's like a simple spreadsheet or calculator but with awesome support for dimensional analysis -- you can attach any units you want to a quantity and it will track it throughout the calculations, and do a best-faith effort to figure out conversions / "what you meant".

For example, here's a quick scratchpatch I used for calculating memory bandwidth / CPU transfer rates: https://instacalc.com/56842


Dimensional analysis is useful when you want to convert between compositions of units. A good example is comparing the price of petrol where different units are being used. If you know the conversion rate between litres and gallons, and the conversion rate between USD and GBP, then you can figure out the conversion rate between USD/gal and GBP/L:

  USD/gal * GBP/USD * gal/L = GBP/L
  1.24 USD = 1 GBP
  1 gal = 3.78541 L
  GBP/USD = 1.24
  gal/L = 3.78541
  USD/gal * 1.24 * 3.78541 = GBP/L
  USD/gal * 4.6939084 = GBP/L
  $4.6939084/gal = £1/L


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


Way back in undergrad I asked why the conversion ratio between electromagnetic and electrostatic charge had the dimensions of meters per second (it's the speed of light, for those who haven't had to drag themselves through Maxwell). The prof pointed out that if you had a soap factory and measured output in pounds per day and also in dollars per day, the conversion ratio of the two output measures would have the dimensions of dollars per pound, which would also happen to be the price of a pound of soap. I just always thought that was neat.


Similarly for the petrol consumption case, once you convert "liters per 100km" to normalized units, you get "square meters". Usually for most cars a value of a few square milimeters. You can intuit this as "sweep the volume of the fuel injector across the distance travelled"; imagine all the petrol used as a very thin cylinder lying along the length of the trip.


The instant consumption of electric cars can be measured as kW which is power, but the overall consumption will more commonly use something like kWh/km which is a force unit (equal to 3600 N); and the ratio between the two is the average speed measured in km/h.

Is this related to the answer of your original question?

[Yes technically you'd more likely see kWh/100km or Wh/km, but the result is a silly unit for speed].


Yeah it gets to the kind of weirdness that a kWh has the same dimensions as a Joule: power is an instantaneous measurement and when integrated over time yields energy: (mass * distance) / (time squared) vs (mass * distance) / (time), to use the engineering sense of d / dt meaning "dividing by a little bit of t" (we were supposed to avoid saying that around people from the mathematics department).

Where it got really interesting was Heisenberg, because the indeterminance relationship doesn't just hold for position and momentum but for any two units whose dimensions multiply out to (mass * distance squared) / (time). So famously meter vs kilogram * meter / second, but more usefully in real life second vs Joule. Or weird combos like mass vs change in area over time, whatever that would mean...


Brings back memories. We had a particularly strict physics teacher who only awarded full marks if our answers were numerically correct, with correct units, and we proved (with a little marginal aside simplifying all mass, length and time) that the dimensions were also correct.


Hmm, that's very standard where I'm from. You're never supposed to operate on bare numbers, but carry the units along in your equations, which automatically proves that the answer has the correct units if you didn't make mistakes. To get full marks you're definitely not allowed to just assume the units in your answer.


Agreed. A plain number as an answer could give you zero points. It is always UNITS UNITS UNITS. 10 what? Kg? Apples? kW?

I remember actually a chemistry test where I did not use units in an important calculation but only in the answer. If I had used units I would have realized that I totally fucked up. I went belly up. :-(

Dimensional analysis was part of my degree but honestly, I remember little.


I had a high school physics teacher who would have the instructions "Answer in SI units unless specified" at the top of his exams, but there was always a last bonus problem that referenced the previous answer and promised extra credit equal to a full problem for the answer in "most creative or interesting units (with work shown)". It was a competition in the class for the extra credit and he'd typically award 1-3 of the answers full extra credit.


I agree, this was a basic sophmore year concept at my mechanical engineering department.


I used the HP48 family of calculators for most high school and college science classes, so it was easy to keep track of units throughout the entire chain of calculations with automatic conversions and a degree of type checking (not quite fully automatic dimensional analysis). I developed a very strong habit of always being explicit about units for any quantity, and was appalled at how lenient many students and instructors were. Worst were the textbooks that defined obscure domain-specific constants without explicitly stating the units, often forcing the reader to reference several pages to be sure of the units in use for that context.


Similarly, I would have never survived college physics without a cheapo CAS calculator that could tag and symbolically manipulate units. I simply made far too many algebra errors without it.


My chemistry teacher was good like that.

Sadly my HS physics teacher often gave us unreasonable values on homeworks and exams so you couldn’t sanity check easily. Eg - a kangaroo jumps 245 meters high, or the barrel of a gun is 1.5 kilometres long, etc.


Why do people do such silly things? Part of working assignments is to grow an intuition, and no kangaroo jumps hundreds of meters. Such crap just reinforces the notion that what you do in school is completely meaningless and divorced from reality.


Reality includes jet packs and moon walks where such numbers can be relevant. It also includes virtual realities like Fortnite in which such jumps are mundane. And the oddity can add interest to the problem while helping to train the intuition with examples outside of the normal box.


then make them relevant. ... don't say kangaroo jumps 500 metres, say an alien from mars jumps x martian units and ask the student to derive a conversion factor between the martian and earthling units.

or some problems with time dilation.

BUT don't call it "kangaroo jumps 50000 km and we need it cause reality says so"


It can also help you understand what physics you should be using / taking account of.

A metal ball travelling 1m at 3 m/s and I’m pretty confident I can get a good approximation using the basic Newtonian equations.

An irregular shaped object like a Kangaroo travelling 50.000 km at presumably many hundred of meters of per second and I need to think about a lot more! Not least that this kangaroo os travelling about one and a quarter times around the world so the spherical nature of the world needs to be taken into account!


Same here, our high school physics teacher drilled that into our heads and 35 years later I still carry through units or do a separate calculation every time.


I always go back to the reference https://gmpreussner.com/research/dimensional-analysis-in-pro... for programming language support. It's updated from time to time, and incorporated the work done on Ada in the 2010s. Good read.


This is criminally under taught and under used


Once I casually mentioned dimensional analysis/quantity calculus to a programmer who worked at CERN, doing scientific computing. They had never heard of it. They had already worked out the hard way that you could do this stuff, but they thought of it as a hack. They were pumped to find out there was a theory behind it and it wasn't just ad-hoc duct taping.

That really surprised me. I'm not that smart or educated. I think they either had a masters degree or were a master's student (can't recall precisely).


Myself i saw it once in a one semester fluid class for two lectures. A class on the Buckingham pi theorem and another on using units to hack simple physical models.

To be fair, fluid engineers and the like see this a lot though (because of All their dim-less numbers). But ECE, physics, CS, chemistry etc majors? Almost nada.


I oppose making a failure to teach dimensional analysis with the physical sciences a crime, but it fits nicely as a tort of professional negligence, aka malpractice. It might be tricky to get that by the teachers unions though.


That makes it an advantage if you learn it early enough. Some physics questions all the way up to college can be trivialised by understanding the units of the inputs and answer.


You can trivialize a lot past grad school with this.


Kind of odd that this doesn't really go into metrics directly nor does it mention one of the more interesting cases which is infinite dimensionality.


Is this the infinite dimensionality you refer to? I asked ChatGPT4:

In the context of dimensional analysis, what is "infinite dimensionality"? Keep your answer brief, only one or two short paragraphs.

In the context of dimensional analysis, the term "infinite dimensionality" typically doesn't refer to the physical dimensions (like length, time, and mass) that one might immediately think of. Instead, in mathematical and theoretical physics contexts, it often pertains to spaces, particularly function spaces, that have an infinite number of dimensions. For instance, the space of all possible functions of a particular type can be thought of as having infinite dimensionality, as each function can be uniquely described by an infinite series of coefficients.

One of the most commonly encountered infinite-dimensional spaces in physics is the Hilbert space, used in quantum mechanics. Here, the state of a quantum system can be represented by a vector in an infinite-dimensional space. While the idea of "infinite dimensionality" might sound abstract and counterintuitive, it provides the necessary mathematical framework to accurately describe and predict a variety of physical phenomena.


That looks off the mark to me - ChatGPT is jumping to the idea of R^∞ spaces and the like. I have no idea what the concept of a "meter^∞/second^∞" dimension would mean.


Well, this gets a bit heavy and is an area I have only modest familiarity with and not all that much practice.

That concept of infinite dimensional meters per infinite dimensional seconds doesn't work. With infinite dimensions that the whole idea of metrics breaks down. This gets used as a tactic: If you want to present some basic spatial concept without defining and then being bound to a specific metric then you might use infinite dimensional spaces for that since they are free of traditionally considered metrics.

This is rather exotic territory. The vast majority of phenomena that people find interesting can be characterized using eight or fewer dimensions.


I suspected so and I hope m0llusk will clarify. I found it frustrating to hear about an interesting missed case without enough context to google, unless you already know about infinite dimensionality in the first place.


"Dimensions" in dimensional analysis are not the same thing as dimensions in linear algebra! I'm not sure what a scalar quantity with an infinite dimension would be. (To reiterate, the dimensions of dimensional analysis tell you how quantities scale under adjustment of our scale of measurement, so having infinite dimension would mean scaling infinitely quickly…?)

That being said, I did try to connect infinite-dimensional problems with dimensional analysis in this post. Towards the end of my section on dimensions with complex powers, I applied dimensional analysis to the study of periodic signals and ended up arguing that (complex) Fourier basis elements can be thought of as dimensionful objects. I haven't seen dimensions used like this before, so I was hoping to earn the vote from fans of functional analysis ;)


I learned this in fluid dynamics class for learning about non dimensional value that are used like Reynolds numbers, but more broadly it was a bit like a cheat code because often we had an exam question with units of inputs and then the final answer in another set of units, and even without knowing the correct equation you could with a little intuition, derive the correct solution by combining the input units in fun ways,

Understanding the MLT system in this way made most of mechanical engineering much more straightforward, and I used this almost every day up to my masters degree in computational fluid dynamics.


Best one-lesson favor I ever got was dimensional analysis in high school.

Do it, and most basic physics is trivial.


Check out this NIST technical note on implementing quantity calculus (the broader topic in which dimensional analysis resides - it has nothing to do with integration or differentiation, don't let the 'calculus' part turn you off) in software.

https://www.nist.gov/publications/architecture-software-assi...


This was interesting, but I was expecting something more along the lines of base units => https://en.wikipedia.org/wiki/International_System_of_Units


Dimensions are a level below units.


Ah, so: "dimensions are the abstract theory of units", then?


In the formalism of both this article and https://news.ycombinator.com/item?id=37517118, "base units" are specially designated physical quantities, while "dimensions" describe how physical quantities scale under changes to the scale of measurement.

Customarily, capital letters like M, T, L, etc., refer to dimensions, and you would something like [1 kg] = M to say that 1 kg is a quantity that scales like a mass. A PLT analogy analogy would be to compare physical quantities to values and dimensions to types.

In practice we can refer to dimensions by base units, but it has some mathematical benefits to view them as distinct. Hope that clarifies things!


It does, thank you.


Dimensions behave somewhat like a "type system" for math. These dimensional-analysis tricks act like the trick you see in Haskell sometimes, where you can easily guess an implementation of an expression once you know it's type (or e.g. search by type signature https://hoogle.haskell.org/ )


Great. Now let's talk about the addition operation not being available for some units / dimensions like Temperature, Density, Speed etc.


How would you convert between Kelvin and Celsius if temperatures couldn't be added?


What does it mean to add temperatures though (serious question)?

Eg: Suppose (one of many subtly different scenarios) you have 1 kg of iron at a constant temperature of 20 C and 5 kg of Aluminium at a constant temperature of 15 C.

What does it mean to add those temperatures?


You tell me. Units help describe what you modeled, they can't stop you from modeling nonsense.

I heated up your iron by 4 degrees and now it's 20C+4C=24C. I modeled the physical process of heating and the units provide some additional information about that.


> I heated up your iron by 4 degrees

and what happened when you applied the same amount of heat to the greater mass of Aluminium?

What's the difference between intensive properties (tempreture, pressure, density) and extensive properties, such as mass or volume?


Again, you tell me. Units have no meaning without the context of what you're modeling.

I can model the average temperature of your pieces of metal as (20C+15C)/2=17.5C.


  Units have no meaning without the context of what you're modeling.
I fully agree with that statement ! But some addition of units are widely accepted because their associated model is almost universal on earth, let's say adding mass (kg) of two different objects


Yes, that's why we're having this conversation. It's so common that some people reasonably infer a stronger connection between units and physics.


As a vague intuition, I think of temperature as some sort of "heat density". It's not right, but it helps.


You can move the numerical value by 4 but it doesnt mean you can add Temperatures You're correct though that as long as you have a very specific working model, you can add Temperatures thanks to it. But that model doesnt propagate to the rest of physics


The 4C there is not really a temperature, though. It's a difference in temperature.

I guess that's a limitation of dimensional analysis, since they both have the same units and dimensions.


Exactly, 4C is a quantity with temperature units. Units have no semantic meaning without context. Dimensioned quantities have the semantic meaning that you give them.


Physicists use the more correct Kelvin scale and you can have conversion functions between Kelvin and others less correct units


Why do we have square meters but not square seconds?


Dimensional analysis crimes are the best crimes. Express velocity in meter-hertz. It's wrong, but the units are right!


Meter-hertz is a natural expression of velocity in some contexts though.

The radius of a rotating disk times the frequency of rotation would give you the tangential velocity.

Or wave speed expressed as the product of wavelength and angular frequency.


Good point. Hertz is weird because it automatically makes one think of frequency but it's really just "per-second". I just read up about Hertz - weird he lived not that long ago. What did they use for frequency before Hertz?


I've seen older literature that just uses "cycles," "kilocycles," and so forth.

It's never abbreviated, so I always assumed the use of a named unit came from the desire to be able to write shorthand like kHz.


I’ve absolutely seen it abbreviated. The wikipedia page even shows a photo of a “1000 kc” crystal resonator.

https://en.wikipedia.org/wiki/Cycle_per_second


Seems annoying if you’re a physicist or RF engineer. The Hertz makes sense.


We just used cycles per second (cps). Or multiples of it. Hertz was simply the name give to this unit, first in 1935, and later was included in the SI units in 1960.


Hertz are really only appropriate for describing cyclical events. But by convention the units are just 1/s, so have fun abusing it.


One interesting property of Hertz is that it's partially appropriate for describing sampling rates. I've found use in annotating separate units for "cycles/sec" and "samples/sec" so I avoid mixing them up (for example, the Nyquist rate can be expressed as 0.5 cyc/smp).


A period of infinity is cyclical /s


Ooh, you could have gone one further and done hertz-per-diopter.


Equating m/s and m·Hz is perfectly correct if you're asked to calculate the linear speed of a vehicle, given the radius of its wheels and their rotation rate, assuming no slippage! This is of course equal, up to a change of frame, to the tangential speed of a point on the wheel rim, as a sibling commenter noted.


Or measuring torque in Watt-hours (or any other unit of energy -- joules, calories, BTUs...).


Obligatory comic: https://xkcd.com/687/


Some crimes can be avoided with Orientational Analysis. Nobody teaches it though.


Well, anyone that does geometric algebra thinks a bit about formal quantities that mix grades.




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

Search: