Troubleshooting - Maple Programming Help

Online Help

All Products    Maple    MapleSim


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

Troubleshooting

 

Description

Changing the Default Context for a Unit

Changing the Conversion Factor for a Unit

Adding a New Unit

Adding Changes to the Initialization File

Working with annotated units such as mradius and contexts such as milenautical.

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). To convert hertz to revolutions per minute the 'symbolic' option must be included. The conversion contains an unwanted factor of 12π.

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

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', '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.

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)
  

 

  

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.

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

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 mradius and contexts such as milenautical.

  

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]

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam