I would suggest finding a package for doing this in your programming language of choice, since you're going to be using that to check/automate your engineering calculations anyways.
For R
The units
library is one option. It looks something like this:
> library('units') > m <- ud_units$m; mm <- ud_units$mm; kN <- ud_units$kN; MPa <- ud_units$MPa > sigma <- 1*kN/(1*m * 1*mm) > units(sigma)= MPa > sigma 1 MPa
If you try an operation that mixes dimensions, it throws an error:
> 1*m + sigma Error: cannot convert MPa into m
However, if you try an operation that mixes units of the same dimensions, it just puts the result in one of those units:
> 1*m + 1*mm 1.001 m
I haven't used the units
library enough to vouch for its stability, but R libraries are typically very stable and well tested.
For Python:
There are a few options available (one of the curses of a language that's popular among CS folks), but I think the magnitude
module is the cleanest looking. It works like this:
>>> from magnitude import mg >>> x= mg(1,'m') >>> y= mg(1,'mm') >>> F= mg(1,'kN') >>> sigma= F/(x*y) >>> print(sigma.ounit('MPa')) 1.0000 MPa
This module still has a semi-serious bug which causes it to give very misleading output if you try to assign an invalid unit to an existing variable. It also has the downside that you can't freely switch between the objects created my mg()
and the usual numeric types. e.g., instead of numpy.pi*mg(5,'m')**2
you'd have to wrap pi in mg()
with no units as in mg(numpy.pi)*mg(5,'m')**2
.