6.2 Using Symbols for Units
There are many ways to use symbols in Mathematica TE. So far, symbols have been used to store values and to represent mathematical variables. This subsection describes another way to use symbols in Mathematica TE.
The idea is to use symbols as "tags" for different types of objects.
Working with physical units gives one simple example. When you specify the length of an object, you want to give not only a number, but also the units in which the length is measured. In standard notation, you might write a length as 12 meters.
You can imitate this notation almost directly in Mathematica TE. You can for example simply use a symbol meters to indicate the units of our measurement.
The symbol meters here acts as a tag, which indicates the units used.
In[1]:= 12 meters
Out[1]=
You can add lengths like this.
In[2]:= % + 5.3 meters
Out[2]=
This gives a speed.
In[3]:= % / (25 seconds)
Out[3]=
This converts to a speed in feet per second.
In[4]:= % /. meters -> 3.28084 feet
Out[4]=
There is in fact a standard Mathematica TE package that allows you to work with units. The package defines many symbols that represent standard types of units. Packages are discussed in Chapter 23.
Load the Mathematica TE package for handling units.
In[5]:= <<Miscellaneous`Units`
The package uses standardized names for units.
In[6]:= 12 Meter/Second
Out[6]=
The function Convert[expr, units] converts to the specified units.
In[7]:= Convert[ %, Mile/Hour ]
Out[7]=
You generally have to give prefixes for units as separate words, but the standard units Kilogram and Centimeter are exceptions; they may be given as Kilogram and Centimeter, as well as Kilo Gram and Centi Meter.
In[8]:= Convert[ 3 Kilo Meter / Hour, Inch / Minute ]
Out[8]=