Units - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : System : Information : Updates : Maple 2017 : updates/Maple2017/Units

Units

• 

The new Simple environment for units makes computations with units easier than ever.  It allows you to work with expressions such as 5mm+x, where x is unassigned, as long as the dimensional analysis of the expression determines there is a valid quantity with units for the variable x.

• 

Since the introduction of the Units package for Maple 7 (in 2001), there have been three ways to compute with unit expressions:

– 

The default units environment, in which you explicitly invoke commands such as combine,units or convert,dimensions whenever you want to use unit functionality. This environment is suitable for expert users.

– 

The Standard units environment, in which unit functionality is enabled for most basic operations. This environment requires that units are explicitly marked as such.

– 

The Natural units environment, in which unit functionality is also enabled for most basic operations. This environment automatically interprets any variable name that corresponds to a unit name, as that unit.

• 

Maple 2017 introduces a fourth way to compute with unit expressions: the Simple units environment. This differs from the Standard and Natural environments in two important ways, both of which make it easier to work with this environment in many cases:

– 

The Standard and Natural environments require that whenever you use an unassigned variable (in the case of the Natural environment, an unassigned variable that is not the name of a unit), it represents a unitless quantity. This rule applies for verifying dimensional correctness - the process that makes sure you cannot add a distance to a velocity, for example. Concretely, you cannot just use a variable called distance to represent a distance to be determined later: instead, you might need to define distance by distancedistance_km km, so that distance is now an assigned variable and distance_km is a unitless quantity representing the number of kilometers that distance is long. This restriction is relaxed for the Simple units environment: unassigned variables are not assumed to have any particular dimension during testing of dimensional correctness.

– 

The Simple units environment disregards so-called unit annotations when verifying dimensional correctness. These annotations are a mechanism to indicate that the physical quantity described by the unit is of a particular type. For example, the unit mile_per_gallon of fuel economy is defined in Maple as milegallonpetroleum; this allows Maple to distinguish it from a unit of the dimension 1length2=1area (which would normally happen when simplifying an expression of the dimension length length3=lengthvolume). Another situation in which these annotations occur is in units of angle: a radian is defined as the angle that describes a circle sector in which the radius and the arc length are the same. This is defined in Maple as the unit mmradius.

  

In many cases, however, users want to combine units while disregarding the unit annotations. This is particularly frequent whenever units of angle crop up. For that reason, the Simple units environment allows the addition of, for example, quantities with the dimension of angle to unitless quantities. The Standard and Natural environments do not.

• 

Before Maple 2017, the default units environment always followed the same approach as the Standard and Natural units environments, with respect to these two issues. In Maple 2017, you can use the new UnitsUseMode command to switch between these two approaches in the default units environment.

Examples

withUnits:-Simple:

Consider a situation where you know an object will undergo uniform acceleration, with an initial velocity of 2.4 meters per second. We can derive the generic formula for the position of the object at an arbitrary time as follows. We start with the general formula for velocity under uniform acceleration.

vv0+at

vat+v0

(1)

Now we substitute the given starting velocity.

evalv,v0=2.4ms

at+2.4ms

(2)

vs

vsat+2.4ms

(3)

Integrating this over time gives the requested answer.

xx0+0t0vsⅆt

xx0+0.5000000000at02+2.400000000t0ms

(4)

Now let's additionally specify that the object starts at the origin, and the acceleration is gravity. We orient our axis of displacement so that the initial velocity was upward, so in the opposite direction to gravity.

gravityevalfScientificConstants:-Constantg,units

gravity9.80665ms2

(5)

evalx,x0=0m,a=gravity

4.903325000t02ms2+2.400000000t0ms

(6)

If we want to know the position after 0.4 seconds, we can obtain it like this.

eval,t0=0.4s

0.1754680000m

(7)

This example comes from the example worksheets for the various units environments; specifically, for the version for the Simple units environment. You can compare the default units example worksheet, the Standard units example worksheet, and the Natural units example worksheet.

The first example shows how you can use unassigned variables to represent quantities that are not unitless. The following example will show a case where it comes in handy that annotations are ignored when verifying dimensional correctness.

Consider tightening a nut using a wrench. You apply a constant torque of 30 newton meters over 6 full rotations. The friction increases the temperature of the nut by 5 degrees Celsius; the nut, which is sizeable, has a mass of 80 grams and is made of steel. Steel has a specific heat capacity of 452 joules per kilogram per Kelvin. How much energy did you expend, how much of it was converted to heat, and how much leaked away into the environment?

torque30.Nm

torque30.Nm

(8)

angle6.revolution

angle6.rev

(9)

nut_mass80.g

nut_mass80.g

(10)

heat_capacity452.JkgK

heat_capacity452.JkgK

(11)

temperature_rise5degC

temperature_rise5°C

(12)

expended_energytorqueangle

expended_energy1130.973355m3kgs2mradius

(13)

heatnut_massheat_capacitytemperature_rise

heat180.8000000J

(14)

leakedexpended_energyheat

leaked950.1733550J

(15)

TestDimensions

• 

At the heart of the Simple units environment is the new command Units[TestDimensions]. This command verifies dimensional correctness of one or more expressions with units. By default, it returns true if there is a valid assignment of dimensions to all subexpressions of expr, and false otherwise. Validity is tested for all subexpressions occurring in expr.

• 

This command can be useful to verify the dimensional validity of, for example, a set of equations involving some quantities with units.

withUnits:

eq1F=ma

eq1F=ma

(16)

eq2F=m2a

eq2F=m2a

(17)

TestDimensionseq1,F::N,a::ms2,m::kg

true

(18)

TestDimensionseq2,F::N,a::ms2,m::kg

false

(19)
• 

If you know the dimension of only some of the quantities occurring in a set of equations, you can derive some things about the dimensions of the other symbols and of composite subexpressions. Sometimes you can fully derive the dimension of some quantities, other times there is not enough information.

TestDimensionseq1,F::N,m::kg,output=units

F::N,a::ms2,m::kg,ma::N

(20)
• 

If there are multiple valid assignments of dimensions to the symbols in an expression (in other words, if there is not enough information to fully determine the dimensions of some quantities), then Maple will make an arbitrary choice.

TestDimensionseq1,F::N,output=units

F::N,a::1,m::N,ma::N

(21)
• 

Instead of expressing the dimension by using a unit of the given expression, Maple can also return the name of the dimension (as it would be returned by convert/dimensions with the base option).

TestDimensionseq1,F::N,m::kg,output=dimensions

F::masslengthtime2,a::lengthtime2,m::mass,ma::masslengthtime2

(22)
• 

In this case, if there is ambiguity in the given set of expressions, Maple will determine an expression representing the fully general dimension for any subexpression. These expressions are mostly useful for programmer access.

resultTestDimensionseq1,F::N,output=dimensions

resultF::masslengthtime2,a::length_t581,1mass_t581,2time_t581,3electric_current_t581,4thermodynamic_temperature_t581,5amount_of_substance_t581,6luminous_intensity_t581,7currency_t581,8amount_of_information_t581,9logarithmic_gain_t581,10,m::length1_t581,1mass1_t581,2time2_t581,3electric_current_t581,4thermodynamic_temperature_t581,5amount_of_substance_t581,6luminous_intensity_t581,7currency_t581,8amount_of_information_t581,9logarithmic_gain_t581,10,ma::masslengthtime2

(23)
• 

By manipulating the result, we can see that the dimension of ma is indeed what is claimed.

result_as_equationsmaplhs=rhs,result

result_as_equationsF=masslengthtime2,a=length_t581,1mass_t581,2time_t581,3electric_current_t581,4thermodynamic_temperature_t581,5amount_of_substance_t581,6luminous_intensity_t581,7currency_t581,8amount_of_information_t581,9logarithmic_gain_t581,10,m=length1_t581,1mass1_t581,2time2_t581,3electric_current_t581,4thermodynamic_temperature_t581,5amount_of_substance_t581,6luminous_intensity_t581,7currency_t581,8amount_of_information_t581,9logarithmic_gain_t581,10,ma=masslengthtime2

(24)

m_dimevalm,result_as_equations

m_dimlength1_t581,1mass1_t581,2time2_t581,3electric_current_t581,4thermodynamic_temperature_t581,5amount_of_substance_t581,6luminous_intensity_t581,7currency_t581,8amount_of_information_t581,9logarithmic_gain_t581,10

(25)

a_dimevala,result_as_equations

a_dimlength_t581,1mass_t581,2time_t581,3electric_current_t581,4thermodynamic_temperature_t581,5amount_of_substance_t581,6luminous_intensity_t581,7currency_t581,8amount_of_information_t581,9logarithmic_gain_t581,10

(26)

expandm_dima_dim=evalma,result_as_equations

masslengthtime2=masslengthtime2

(27)