I am surprised that there are some cases where unit conversion works, even if the input- and output dimensions are clearly different:
UnitConvert[Quantity[1., 1/"Meters"], "Centimeters"]
(* returns 0.01/cm *)
Also, the following (and many, more complicated inputs) work. It seems that when you have a compound unit at the input, and a single unit for the output, Mathematica only converts the specified "dimension" (length, time, ...) and any power of that dimension (length^n, ...):
UnitConvert[Quantity[1., "Amperes"/"Meters"], "Centimters"]
(* returns 0.01 A/cm *)
UnitConvert[Quantity[1., "Meters"*"Kilograms"/"Amperes"], "Pounds"]
(* returns 2.20462 lb m/A *)
UnitConvert[Quantity[1., "Meters"*"Feet"*"Kilograms"/"Amperes"], "Centimeters"]
(* returns 3048 kg cm^2/A *)
While this is a convenient shortcut to simplify compound units, it also seems dangerous, since this behaviour is not specified in the documentation.
Also, I am using units in my calculations to ensure I am not making trivial errors in entering formulas or input values. I need Mathematica to throw an error when it encounters such incompatible unit conversions.
Is this a feature (to be specified as such in future versions) or a bug (likely to be fixed in future versions)? And is there perhaps a way to specify a "strict" behaviour for UnitConvert
?
Amperes/Meters
, which you can "convert" toCentimeters
. On the other hand, Mathematica throws an error when trying to convertSeconds
toMegahertz
, even though these are pure, reciprocral "unit-dimensions". $\endgroup$