Units - Maple Programming Help

Home : Support : Online Help : Science and Engineering : Units : Combining : Units/UseMode

Units

 UseMode
 set the default mode for combining units

 Calling Sequence UseMode(mode)

Parameters

 mode - (optional) symbol; name of mode for combining units

Description

 • The combine/units command can be used with several modes for combining units, corresponding to subpackages of the Units package. The UseMode(mode) function sets a default mode for combining units, to be used for the current session.
 • The modes available are currently simple, standard, and natural, corresponding to the Units/Simple, Units/Standard, and Units/Natural subpackages, respectively. If you load any of these packages, Maple will automatically call UseMode with the corresponding argument.
 • When you load the Units package, Maple will automatically load the subpackage corresponding to the currently selected mode.
 • Additionally, the mode set by this command determines the default for the symbolic option of the convert/units command. In simple mode, the conversions happen with symbolic = true by default; in the two other modes, the default is symbolic = false.
 • The default mode if none of these packages have been loaded is simple.
 • Calling the UseMode command manually can be useful if you use the default Units environment, i.e., without loading any packages, and you wish to select how combine/units should combine units. It can also be useful to do this before loading the Units package, to instruct it which subpackage to load.
 • The setting effected by the UseMode command applies to any calls to combine/units made by the user themselves, but also to calls from inside other commands, such as plot and int.
 • The UseMode command returns the previous mode that was in effect. When called without any arguments, its only effect is to return the current mode.
 • To set a default mode for combining units for all future Maple sessions, add the UseMode command to your Maple initialization file. For more information, see Create Maple Initialization File.

Examples

Notes:

 – To enter a unit in 2-D Math input, select the unit from the appropriate Units palette. If the unit you want is not there, select $\mathrm{unit}$ and then enter the unit.
 – When you edit a unit, double brackets appear around it.

The default setting if none of the Units environments have been loaded is simple.

 > $\mathrm{Units}\left[\mathrm{UseMode}\right]\left(\right)$
 ${\mathrm{simple}}$ (1)

We can see this because combine/units accepts the following expression, which assumes the unassigned variable $\mathrm{distance}$ has a unit of length.

 > $\mathrm{combine}\left(\mathrm{distance}+30\mathrm{Unit}\left(\mathrm{km}\right),'\mathrm{units}'\right)$
 ${\mathrm{distance}}{+}{30}{}⟦{\mathrm{km}}⟧$ (2)

In either the Units/Standard or Units/Natural model, this expression is invalid. Notice that if we select the standard units mode, executing the same expression results in an error about adding $\mathrm{distance}$, which is now implicitly unitless, and the term with a unit.

 > $\mathrm{Units}\left[\mathrm{UseMode}\right]\left(\mathrm{standard}\right)$
 ${\mathrm{simple}}$ (3)
 > $\mathrm{combine}\left(\mathrm{distance}+30\mathrm{Unit}\left(\mathrm{km}\right),'\mathrm{units}'\right)$

To verify that the correct mode was stored, we can call the UseMode command again.

 > $\mathrm{Units}\left[\mathrm{UseMode}\right]\left(\right)$
 ${\mathrm{standard}}$ (4)

With the currently selected mode, the default value for the symbolic option of the convert/units command is false. This means, for example, that Maple distinguishes between angles and unitless quantities, and between torque and energy; you cannot convert one to the other.

 > $\mathrm{convert}\left(2.4,'\mathrm{units}','N''m'\left('\mathrm{radius}'\right),'\mathrm{Btu}'\right)$

If we supply the option symbolic = true, or if we switch to the simple mode, then this conversion succeeds, with the implicit understanding that it is the energy required for applying the torque over an angle of one radian.

 > $\mathrm{convert}\left(2.4,'\mathrm{units}','N''m'\left('\mathrm{radius}'\right),'\mathrm{Btu}','\mathrm{symbolic}'='\mathrm{true}'\right)$
 ${0.002276283395}$ (5)
 > $\mathrm{Units}\left[\mathrm{UseMode}\right]\left('\mathrm{simple}'\right)$
 ${\mathrm{standard}}$ (6)
 > $\mathrm{convert}\left(2.4,'\mathrm{units}','N''m'\left('\mathrm{radius}'\right),'\mathrm{Btu}'\right)$
 ${0.002276283395}$ (7)

If we load the Units[Standard] package in a new Maple session to enable the Standard Units environment, the standard mode is automatically selected.

 > $\mathrm{restart}$
 > $\mathrm{with}\left(\mathrm{Units}\left[\mathrm{Standard}\right]\right)$
 $\left[{\mathrm{*}}{,}{\mathrm{+}}{,}{\mathrm{-}}{,}{\mathrm{/}}{,}{\mathrm{<}}{,}{\mathrm{<=}}{,}{\mathrm{<>}}{,}{\mathrm{=}}{,}{\mathrm{\Im }}{,}{\mathrm{\Re }}{,}{\mathrm{^}}{,}{\mathrm{abs}}{,}{\mathrm{add}}{,}{\mathrm{arccos}}{,}{\mathrm{arccosh}}{,}{\mathrm{arccot}}{,}{\mathrm{arccoth}}{,}{\mathrm{arccsc}}{,}{\mathrm{arccsch}}{,}{\mathrm{arcsec}}{,}{\mathrm{arcsech}}{,}{\mathrm{arcsin}}{,}{\mathrm{arcsinh}}{,}{\mathrm{arctan}}{,}{\mathrm{arctanh}}{,}{\mathrm{argument}}{,}{\mathrm{ceil}}{,}{\mathrm{collect}}{,}{\mathrm{combine}}{,}{\mathrm{conjugate}}{,}{\mathrm{cos}}{,}{\mathrm{cosh}}{,}{\mathrm{cot}}{,}{\mathrm{coth}}{,}{\mathrm{csc}}{,}{\mathrm{csch}}{,}{\mathrm{csgn}}{,}{\mathrm{diff}}{,}{\mathrm{eval}}{,}{\mathrm{evalc}}{,}{\mathrm{evalr}}{,}{\mathrm{exp}}{,}{\mathrm{expand}}{,}{\mathrm{factor}}{,}{\mathrm{floor}}{,}{\mathrm{frac}}{,}{\mathrm{int}}{,}{\mathrm{ln}}{,}{\mathrm{log}}{,}{\mathrm{log10}}{,}{\mathrm{max}}{,}{\mathrm{min}}{,}{\mathrm{mul}}{,}{\mathrm{normal}}{,}{\mathrm{polar}}{,}{\mathrm{root}}{,}{\mathrm{round}}{,}{\mathrm{sec}}{,}{\mathrm{sech}}{,}{\mathrm{seq}}{,}{\mathrm{shake}}{,}{\mathrm{signum}}{,}{\mathrm{simplify}}{,}{\mathrm{sin}}{,}{\mathrm{sinh}}{,}{\mathrm{sqrt}}{,}{\mathrm{surd}}{,}{\mathrm{tan}}{,}{\mathrm{tanh}}{,}{\mathrm{trunc}}{,}{\mathrm{type}}{,}{\mathrm{verify}}\right]$ (8)
 > $\mathrm{Units}\left[\mathrm{UseMode}\right]\left(\right)$
 ${\mathrm{standard}}$ (9)

This means that the combine command we used above will throw an error, as before.

 > $\mathrm{combine}\left(\mathrm{distance}+30\mathrm{Unit}\left(\mathrm{km}\right),'\mathrm{units}'\right)$

You can override the mode by calling UseMode again, or by explicitly supplying the mode option to the combine/units command. In either case, you need to be careful, otherwise the addition operator, +, generates an error before it gets to combine/units. This can be overcome by explicitly using the top level version of + instead of the one from the Units[Standard] package.

 > $\mathrm{combine}\left(:-\mathrm{+}\left(\mathrm{distance},30\mathrm{Unit}\left(\mathrm{km}\right)\right),'\mathrm{units}','\mathrm{mode}'='\mathrm{simple}'\right)$
 ${\mathrm{distance}}{+}{30}{}⟦{\mathrm{km}}⟧$ (10)

Loading the Units package also loads one of the Units subpackages, as indicated by the currently selected mode. By default, this is the Units[Simple] subpackage, but this can be overridden using the UseMode command.

 > $\mathrm{restart}$
 > $\mathrm{with}\left(\mathrm{Units}\right):$
 > $\mathrm{restart}$
 > $\mathrm{Units}\left[\mathrm{UseMode}\right]\left(\mathrm{standard}\right)$
 ${\mathrm{simple}}$ (11)
 > $\mathrm{with}\left(\mathrm{Units}\right):$