Troubleshooting - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Troubleshooting

 

Description

Changing the Default Context for a Unit

Changing the Conversion Factor for a Unit

Adding a New Unit

Dealing with Empirical Temperatures

Adding Changes to the Initialization File

Working with Annotated Units Such as m(radius) and Contexts Such as mile[nautical]

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');

langleyenergy,langleypower

(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');

langley,context=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.

Units[AddUnit]('langley', 'context'='power', 'default'):

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 (1s). The conversion contains an unwanted factor of 12π.

convert(16, 'units', 'Hz', 'rpm');

480π

(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.

Units[AddUnit]('hertz', 'context'='SI', 'conversion'=2*Pi*'radian'/'s', 'check'=false);

convert(16, 'units', 'Hz', 'rpm');

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.

Units[AddUnit]('mile', 'context'='standard', 'conversion'=1609*'m', 'check'=false);

Units[AddUnit]('mile_per_hour', 'context'='standard', 'conversion'=1609*'m'/'h', 'check'=false);

convert(100, 'units', 'mph', 'km'/'h');

160910

(7)

Adding a New Unit

  

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.

Units[AddUnit]('movie', 'context'='duration', 'conversion'=1.5*'h', 'spellings'={'movies'});

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.

Units[AddBaseUnit]('rating', 'context'='stars', 'dimension'='quality');

Dealing with Empirical Temperatures

  

Expressions with a unit are represented in Maple as a product of the expression with a function call, which can be obtained by calling the procedure Unit. This means that Maple cannot represent the expression 0 with a unit: it would be represented as, for example, 0·ⅆⅇgC, or internally, 0·UnitdegC, but 0 multiplied by any function call immediately simplifies to 0. This particularly comes up with temperatures sometimes, when dealing with empirical temperatures rather than with temperature differences. This can be a reason to use Temperature objects instead of regular unit expressions.

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(radius) and Contexts Such as mile[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.

See Also

convert

help

Initialization File

Units

Units/annotations

Units[AddBaseUnit]

Units[AddUnit]

Units[GetUnit]

Units[GetUnits]