Quantity

Quantity[magnitude,unit]

represents a quantity with size magnitude and unit specified by unit.

Quantity[unit]

assumes the magnitude of the specified unit to be 1.

Details

  • In Quantity[m,u], the unit u can be given as a string, such as "Meters", or a product of powers of units, such as "Meters"/"Seconds"^2.
  • Supported units include all those specified by NIST Special Publication 811.
  • Quantity expresses temperatures using units such as "DegreesCelsius" and temperature differences using units such as "DegreesCelsiusDifference". Quantity arithmetic operations systematically distinguish this.
  • Quantity operations systematically distinguish temperatures, expressed using units such as "DegreesCelsius", from temperature differences, expressed using units such as "DegreesCelsiusDifference".
  • Quantity[unit] will produce a canonicalized Quantity with a magnitude of 1.
  • Quantity expressions can be created by using the free-form linguistics interface.
  • Quantity will automatically attempt to parse an unknown unit string to its canonical form.
  • Quantity has attribute HoldRest and preserves the structure of unit.
  • For purely numeric units, such as percents, Normal[expr] converts a Quantity object to an ordinary number.
  • Information of a Quantity may include the following properties:
  • "Magnitude"quantity magnitude
    "Unit"unit associated with the quantity
    "UnitDimensions"physical dimensions of unit
    "SIBaseUnits"SI base units

Examples

open allclose all

Basic Examples  (4)

A Quantity represents a value associated with a specific unit:

Use to enter quantities and units:

Compound unit expressions can also be found using :

A unit can be a string or a product of strings:

Valid unit specifications include a number of physical constants:

Quantity will automatically attempt to interpret an unknown unit string:

Scope  (7)

Quantity expressions can be used in comparison functions:

Use MixedMagnitude and MixedUnit specifications to define a mixed Quantity:

Quantity expressions can be used in various list operations:

Many numerical functions also operate on Quantity expressions:

Integer functions also operate on Quantity expressions:

Normal will return the fundamental value for dimensionless Quantity expressions:

N may be used to numericize Quantity expressions:

N will not change the units associated with a Quantity expression, including physical constants:

UnitConvert can be used to find the SI value of physical constants:

Applications  (2)

Use FormulaData with Quantity objects to determine the escape velocity of the Earth and of the Sun:

Use FormulaData with Quantity objects to visualize the spectral radiance of a black body at temperature 5000 kelvins as a function of wavelength:

Properties & Relations  (15)

A unit can be given as a string or product of strings:

IndependentUnit specifications can also be used:

Units accept prefixes that are used to form decimal multiples and submultiples of units:

In its one-argument form, Quantity automatically sets the magnitude to 1:

The first argument of Quantity can also be a Quantity object, in which case units are multiplied:

Additions of Quantity objects with compatible units will heuristically determine the result units:

Products of Quantity objects with compatible units will heuristically determine the result units:

Subtraction of temperatures in non-absolute scales like Celsius or Fahrenheit produces temperature differences:

Addition of a temperature and a temperature difference gives another temperature:

Operations involving products and divisions of temperatures may convert automatically to kelvins:

This result is equivalent to converting the temperature in advance:

Quantity threads its unit specification over lists:

Canonical unit strings are always plural. Unit descriptions will accurately reflect the singular form of a unit:

Since Quantity is HoldRest, it can accept multiple unit strings of the same dimension:

When quantities are multiplied, the resulting unit is not automatically simplified:

Use UnitSimplify to get a simpler form of the unit:

Use UnitConvert to normalize mixed Quantity expressions to non-mixed Quantity expressions:

Use QuantityArray to describe rectangular arrays of Quantity objects of common units:

Normal converts the structured array into an equivalent normal array of Quantity objects:

Possible Issues  (2)

Quantity automatically attempts to interpret unrecognized unit strings as canonical units:

Expressions composed of unrecognized unit strings cannot be interpreted in this way:

Instead, the unit should be specified as a single string:

Some units contain Interval expressions, which can result in comparisons returning unevaluated:

Wolfram Research (2012), Quantity, Wolfram Language function, https://reference.wolfram.com/language/ref/Quantity.html (updated 2022).

Text

Wolfram Research (2012), Quantity, Wolfram Language function, https://reference.wolfram.com/language/ref/Quantity.html (updated 2022).

CMS

Wolfram Language. 2012. "Quantity." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/Quantity.html.

APA

Wolfram Language. (2012). Quantity. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Quantity.html

BibTeX

@misc{reference.wolfram_2024_quantity, author="Wolfram Research", title="{Quantity}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/Quantity.html}", note=[Accessed: 18-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_quantity, organization={Wolfram Research}, title={Quantity}, year={2022}, url={https://reference.wolfram.com/language/ref/Quantity.html}, note=[Accessed: 18-December-2024 ]}