({{, (RefLink[CompatibleUnitQ, paclet:ref/CompatibleUnitQ])[(Subscript[quantity, 1]),(Subscript[quantity, 2])] 
returns (RefLink[True, paclet:ref/True]) if (Subscript[quantity, 1]) and (Subscript[quantity, 2]) have compatible units, and (RefLink[False, paclet:ref/False]) otherwise.}})

OpenersNotesSection(Spacer1)Details

(Subscript[quantity, i]) can be a (RefLink[Quantity, paclet:ref/Quantity]) object or a unit expression, such as "Meters" or "Feet"/"Seconds".

(RefLink[CompatibleUnitQ, paclet:ref/CompatibleUnitQ]) returns (RefLink[False, paclet:ref/False]) unless the (RefLink[Quantity, paclet:ref/Quantity]) or unit elements have the same (RefLink[UnitDimensions, paclet:ref/UnitDimensions]).

(RefLink[CompatibleUnitQ, paclet:ref/CompatibleUnitQ])[quantity] tests whether quantity is a valid (RefLink[Quantity, paclet:ref/Quantity]) or unit expression.

(RefLink[CompatibleUnitQ, paclet:ref/CompatibleUnitQ])[(Subscript[quantity, 1]),…,(Subscript[quantity, n])] tests whether all (Subscript[quantity, i]) expressions have compatible units.

OpenersPrimaryExamplesSection(Spacer1)Examples  (15)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Test whether two (RefLink[Quantity, paclet:ref/Quantity]) objects are compatible:

CompatibleUnitQ[(Quantity[3, "ft", feet, "Feet"]),(Quantity[8, "m", meters, "Meters"])]

Test whether two units are compatible:

CompatibleUnitQ["Feet","Pounds"]

Test compatibility of a sequence of quantities and units:

CompatibleUnitQ[Quantity[3,"Meters"],Quantity[6,"Yards"],"Kilometers"]

OpenersExampleSection1(Spacer1)Scope  (6)

Test compatibility of (RefLink[Quantity, paclet:ref/Quantity]) objects:

CompatibleUnitQ[Quantity[2.5,"Seconds"],Quantity[4/3,"Minutes"]]

CompatibleUnitQ[Quantity[2,"Seconds"],Quantity[1.3,"Meters"/"Seconds"]]

Test compatibility of unit expressions:

CompatibleUnitQ["Becquerels","Seconds"^-1,"Hertz"]

Test compatibility of the elements of lists:

CompatibleUnitQ[{(Quantity[100, "m", meters, "Meters"]),{(Quantity[1, "mi", miles, "Miles"]),(Quantity[3, "km", kilometers, "Kilometers"])}}]

CompatibleUnitQ[{"Meters","Centimeters","Years"}]

Test whether (RefLink[QuantityArray, paclet:ref/QuantityArray]) objects have compatible units:

CompatibleUnitQ[QuantityArray[{2.3,1.5,9.0},"ArcMinutes"]]

CompatibleUnitQ[QuantityArray[{{1,2},{3,4},{5,6}},{"Meters","Seconds"}]]

Use (RefLink[MixedUnit, paclet:ref/MixedUnit]) specifications:

qa=Quantity[MixedMagnitude[{1,80}],MixedUnit[{"Meters","Centimeters"}]]
qb=Quantity[MixedMagnitude[{5,10}],MixedUnit[{"Feet","Inches"}]]

CompatibleUnitQ[qa,qb,"Yards"]

Use (RefLink[DatedUnit, paclet:ref/DatedUnit]) specifications:

CompatibleUnitQ[DatedUnit["Kelvins",1967],"DegreesCelsius"]

CompatibleUnitQ[DatedUnit["Meters",1889],DatedUnit["Kilograms",1889]]

OpenersExampleSection3(Spacer1)Properties & Relations  (6)

(RefLink[CompatibleUnitQ, paclet:ref/CompatibleUnitQ]) returns (RefLink[True, paclet:ref/True]) when its elements have the same (RefLink[UnitDimensions, paclet:ref/UnitDimensions]):

CompatibleUnitQ[(Quantity[10, "m", meters, "Meters"]),(Quantity[7, "in", inches, "Inches"])]

UnitDimensions/@{(Quantity[10, "m", meters, "Meters"]),(Quantity[7, "in", inches, "Inches"])}

An (RefLink[IndependentUnit, paclet:ref/IndependentUnit]) object is only compatible with itself:

CompatibleUnitQ[IndependentUnit["myUnits"],IndependentUnit["myUnits"]]

CompatibleUnitQ[Quantity[3,IndependentUnit["myUnits"]],Quantity[-2,"Nano"IndependentUnit["myUnits"]]]

Known units are not compatible with (RefLink[IndependentUnit, paclet:ref/IndependentUnit]) objects of the same name:

CompatibleUnitQ["Meters",IndependentUnit["Meters"]]

Numeric expressions are treated as dimensionless quantities:

CompatibleUnitQ[Quantity[50,"Percent"],π]

(RefLink[CompatibleUnitQ, paclet:ref/CompatibleUnitQ]) will automatically attempt to interpret an unknown unit string:

KnownUnitQ["Henryes"]

CompatibleUnitQ["Seconds"/"Siemens","Henryes"]

KnownUnitQ["Henries"]

(RefLink[CompatibleUnitQ, paclet:ref/CompatibleUnitQ]) with one argument is similar to (RefLink[KnownUnitQ, paclet:ref/KnownUnitQ]):

{CompatibleUnitQ["Meters"],KnownUnitQ["Meters"]}

(RefLink[CompatibleUnitQ, paclet:ref/CompatibleUnitQ]) accepts numeric expressions:

{CompatibleUnitQ[3],KnownUnitQ[3]}

(RefLink[CompatibleUnitQ, paclet:ref/CompatibleUnitQ]) attempts to interpret unknown unit strings:

{CompatibleUnitQ["second"],KnownUnitQ["second"]}

If elements other than quantities and units are present, (RefLink[CompatibleUnitQ, paclet:ref/CompatibleUnitQ]) returns (RefLink[False, paclet:ref/False]):

CompatibleUnitQ[Quantity[1,"Feet"],x]

CompatibleUnitQ[x]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Quantity, paclet:ref/Quantity])  ▪  (RefLink[UnitDimensions, paclet:ref/UnitDimensions])  ▪  (RefLink[UnitConvert, paclet:ref/UnitConvert])  ▪  (RefLink[KnownUnitQ, paclet:ref/KnownUnitQ])  ▪  (RefLink[MixedUnit, paclet:ref/MixedUnit])  ▪  (RefLink[DatedUnit, paclet:ref/DatedUnit])  ▪  (RefLink[IndependentUnit, paclet:ref/IndependentUnit])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Units Overview, paclet:tutorial/UnitsOverview])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Units & Quantities, paclet:guide/Units])}})}})