Troubleshooting - Maple Programming Help

Home : Support : Online Help : Science and Engineering : Units : Units/Troubleshooting

Troubleshooting

Description

 The Units package provides a comprehensive facility for converting and using units. As a result of its complexity, there are situations in which you may need to customize the package. You may want to change a default context, change a conversion factor, or add a new unit.

Changing the Default Context for a Unit

 If the Units package returns an error or an incorrect conversion factor, you should check whether you are referencing the desired context of the unit. For example, consider the unit called the langley.
 To determine all contexts of the langley, use the GetUnits function.
 > Units[GetUnits]('name'='langley');
 ${{\mathrm{langley}}}_{{\mathrm{energy}}}{,}{{\mathrm{langley}}}_{{\mathrm{power}}}$ (1)
 The langley has two contexts, energy and power.
 To determine the default context of the langley, use the GetUnit (not GetUnits) function with the context option.
 > Units[GetUnit]('langley', 'context');
 ${\mathrm{langley}}{,}{\mathrm{context}}{=}{\mathrm{energy}}$ (2)
 The default context is energy.
 A unit name can represent units with different dimensions. For the units associated with each dimension, there is a distinct help page. To find the one or more help pages that contain information about the langley, use the help command as follows.
 > help('Units'[convert('langley[energy]', 'dimensions')]);
 On the surface energy density page, there is no reference to the power langley. To find the associated help page, use the following command.
 > help('Units'[convert('langley[power]', 'dimensions')]);
 To set the power langley as the default, use the AddUnit function.

Changing the Conversion Factor for a Unit

 The conversion factor for a unit may not agree with your conventions. For example, the hertz is defined as a cycle per second, but is implemented, in accordance with SI, as an inverse second ($\frac{1}{s}$). To convert hertz to revolutions per minute the 'symbolic' option must be included. The conversion contains an unwanted factor of $\frac{1}{2\mathrm{\pi }}$.
 > convert(16, 'units', 'Hz', 'rpm', 'symbolic');
 $\frac{{480}}{{\mathrm{π}}}$ (3)
 In this case, the hertz should be redefined as a revolution per second, that is, 2*Pi*radians/s. You must add the 'check'=false option to the AddUnit command because it changes the value of an existing unit.
 > convert(16, 'units', 'Hz', 'rpm', 'symbolic');
 ${960}$ (4)
 This is the desired result.
 A value based on scientific observation is modified as the accuracy of measurements increase.  For example, a meter of mercury at 0 degrees Celsius is currently accepted to be $133.322$ kilopascals.
 > convert(1, 'units', 'mHg[0degC]', 'kPa');
 ${133.3220000}$ (5)
 The following sets the value to $133.32247$ kilopascals:
 > Units[AddUnit]('meters_mercury', 'context'=0degC, 'conversion'=133.32247*'kPa', 'check'=false);
 > convert(1, 'units', 'mHg[0degC]', 'kPa');
 ${133.3224700}$ (6)
 Note: Changes are not automatically propagated.  For example, changing the definition of the mile does not modify the unit miles_per_hour. Each must be changed separately.
 > convert(100, 'units', 'mph', 'km'/'h');
 $\frac{{1609}}{{10}}$ (7)
 Although great care was taken to ensure the correctness of conversion factors in the Units package, it is possible that there are errors.  Problems of this sort can be solved by using the AddUnit function as in the preceding examples.

 The Units package is comprehensive. However, you may want to add additional units.
 If the new unit has a dimension that is a product of powers of existing dimensions, use the AddUnit function with appropriate context and conversion options. Other options can be included, but are not required.
 > convert(1, 'units', 'day', 'movies');
 ${16.00000000}$ (8)
 If the new unit is associated with a new dimension, then both the unit and dimension are added by using the AddBaseUnit function. The 'context' and 'dimension' options are required.

Adding Changes to the Initialization File

 To customize your Maple session with the changes described above, add them to your Maple initialization file. A sample of code that can be added to your initialization file is:
 > # change context of the langley  Units[AddUnit]('langley', 'context'='power', 'default'):  # set hertz to 2 Pi radians per second  Units[AddUnit]('hertz', 'context'='SI', 'conversion'=2*Pi*'radian'/'s', 'check'=false):  # set a meter of mercury at 0 degrees C to 133.32258 kilopascals  Units[AddUnit]('meter_mercury', 'context'=0degC, 'conversion'=133.32258*'kPa', 'check'=false):  # define a mile to be exactly 1609 meters  Units[AddUnit]('mile', 'context'='standard', 'conversion'=1609*'m', 'check'=false):  # define a mile per hour to be exactly 1609 meters per hour  Units[AddUnit]('mile_per_hour', 'context'='standard', 'conversion'=1609*'m'/'h', 'check'=false):

Working with annotated units such as $m\left(\mathrm{radius}\right)$ and contexts such as ${\mathrm{mile}}_{\mathrm{nautical}}$.

 This is best explained on the Units/annotations help page. In short, a unit with an annotation in parentheses means the same as that unit without the parentheses, except the physical quantity being described is of a particular type; a unit with a context as index describes an alternative definition of the unit itself.