CompatibleUnitQ[quantity1,quantity2]
returns True if quantity1 and quantity2 have compatible units, and False otherwise.
CompatibleUnitQ
CompatibleUnitQ[quantity1,quantity2]
returns True if quantity1 and quantity2 have compatible units, and False otherwise.
Details
- quantityi can be a Quantity object or a unit expression, such as "Meters" or "Feet"/"Seconds".
- CompatibleUnitQ returns False unless the Quantity or unit elements have the same UnitDimensions.
- CompatibleUnitQ[quantity] tests whether quantity is a valid Quantity or unit expression.
- CompatibleUnitQ[quantity1,…,quantityn] tests whether all quantityi expressions have compatible units.
- CompatibleUnitQ[{quantity1,…,quantityn}] is equivalent to CompatibleUnitQ[quantity1,…,quantityn].
- Units of temperature are considered compatible with units of temperature difference.
Examples
open all close allBasic Examples (3)
Test whether two Quantity objects are compatible:
CompatibleUnitQ[Quantity[3, "Feet"], Quantity[8, "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"]Scope (6)
Test compatibility of 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, "Meters"], {Quantity[1, "Miles"], Quantity[3, "Kilometers"]}}]CompatibleUnitQ[{"Meters", "Centimeters", "Years"}]Test whether 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 MixedUnit specifications:
qa = Quantity[MixedMagnitude[{1, 80}], MixedUnit[{"Meters", "Centimeters"}]]
qb = Quantity[MixedMagnitude[{5, 10}], MixedUnit[{"Feet", "Inches"}]]CompatibleUnitQ[qa, qb, "Yards"]Use DatedUnit specifications:
CompatibleUnitQ[DatedUnit["Kelvins", 1967], "DegreesCelsius"]CompatibleUnitQ[DatedUnit["Meters", 1889], DatedUnit["Kilograms", 1889]]Properties & Relations (6)
CompatibleUnitQ returns True when its elements have the same UnitDimensions:
CompatibleUnitQ[Quantity[10, "Meters"], Quantity[7, "Inches"]]UnitDimensions /@ {Quantity[10, "Meters"], Quantity[7, "Inches"]}An 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 IndependentUnit objects of the same name:
CompatibleUnitQ["Meters", IndependentUnit["Meters"]]Numeric expressions are treated as dimensionless quantities:
CompatibleUnitQ[Quantity[50, "Percent"], π]CompatibleUnitQ will automatically attempt to interpret an unknown unit string:
KnownUnitQ["Henryes"]CompatibleUnitQ["Seconds" / "Siemens", "Henryes"]KnownUnitQ["Henries"]CompatibleUnitQ with one argument is similar to KnownUnitQ:
{CompatibleUnitQ["Meters"], KnownUnitQ["Meters"]}CompatibleUnitQ accepts numeric expressions:
{CompatibleUnitQ[3], KnownUnitQ[3]}CompatibleUnitQ attempts to interpret unknown unit strings:
{CompatibleUnitQ["second"], KnownUnitQ["second"]}If elements other than quantities and units are present, CompatibleUnitQ returns False:
CompatibleUnitQ[Quantity[1, "Feet"], x]CompatibleUnitQ[x]Possible Issues (1)
See Also
Quantity UnitDimensions UnitConvert KnownUnitQ MixedUnit DatedUnit IndependentUnit
Function Repository: UnitAdjust
Tech Notes
Related Guides
Text
Wolfram Research (2012), CompatibleUnitQ, Wolfram Language function, https://reference.wolfram.com/language/ref/CompatibleUnitQ.html (updated 2022).
CMS
Wolfram Language. 2012. "CompatibleUnitQ." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/CompatibleUnitQ.html.
APA
Wolfram Language. (2012). CompatibleUnitQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CompatibleUnitQ.html
BibTeX
@misc{reference.wolfram_2026_compatibleunitq, author="Wolfram Research", title="{CompatibleUnitQ}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/CompatibleUnitQ.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_compatibleunitq, organization={Wolfram Research}, title={CompatibleUnitQ}, year={2022}, url={https://reference.wolfram.com/language/ref/CompatibleUnitQ.html}, note=[Accessed: 12-June-2026]}