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

Home : Support : Online Help : indexfcn/Units

The Units Indexing Function

Description

 • A Unit of measurement can be added as the indexing function when constructing an rtable.  Subsequent queries into the rtable will return the underlying quantity times the given Unit.  This indexing function allows you to keep the Unit and data separate, notably allowing datatype=float[8] on an array of quantities involving units.
 • This indexing function is designed to work identically to a rtable without a Unit indexing function, so it can be used as a starting point initially with a fixed unit, and not trigger errors when some or all entries deviate from that unit.  The underlying mechanism keeps the unit separate from the data.  When an entry is assigned that does not match the default unit, a new mirror-rtable containing only units is created and added to the indexing function.  The rtable_split_unit command allows you to extract and separate the data from the unit.
 A consequence of this design is that all assignments need to have the Unit specified in the assigned value, even at initialization.  Initializing an rtable with another rtable that is purely numeric (with no units) will result in a purely numeric rtable with all entries marked as unitless (unless those entries are zero).  The rtable_set_indfn can be used to add a units indexing function to an existing rtable, but be advised that this function always works in-place.

Examples

In this example we separate the data from the unit in order to perform a fast operation (for simplicity we raise to the power of 4), and then create a result with a new unit attached.

 > $M≔\mathrm{Matrix}\left(2,\left(i,j\right)↦\left(10\cdot i+j\right)\cdot \mathrm{Unit}\left(m\right),\mathrm{shape}=\mathrm{Unit}\left(m\right),\mathrm{datatype}=\mathrm{float}\left[8\right]\right)$
 ${M}{≔}\left[\begin{array}{cc}{11.}{}⟦{m}⟧& {12.}{}⟦{m}⟧\\ {21.}{}⟦{m}⟧& {22.}{}⟦{m}⟧\end{array}\right]$ (1)
 > $\mathrm{split}≔\mathrm{rtable_split_unit}\left(M\right)$
 ${\mathrm{split}}{≔}\left[⟦{m}⟧{,}\left[\begin{array}{cc}{11.}& {12.}\\ {21.}& {22.}\end{array}\right]\right]$ (2)
 > $\mathrm{default_unit}≔\mathrm{split}\left[1\right]$
 ${\mathrm{default_unit}}{≔}⟦{m}⟧$ (3)
 > $\mathrm{data}≔\mathrm{split}\left[2\right]$
 ${\mathrm{data}}{≔}\left[\begin{array}{cc}{11.}& {12.}\\ {21.}& {22.}\end{array}\right]$ (4)
 > $\mathrm{newdata}≔{\mathrm{data}}^{4}$
 ${\mathrm{newdata}}{≔}\left[\begin{array}{cc}{413557.}& {439164.}\\ {768537.}& {816124.}\end{array}\right]$ (5)
 > $\mathrm{newM}≔\mathrm{rtable_set_indfn}\left(\mathrm{newdata},\mathrm{Units}:-\mathrm{Simple}:-\mathrm{simplify}\left({\mathrm{default_unit}}^{4}\right)\right)$
 ${\mathrm{newM}}{≔}\left[\begin{array}{cc}{413557.}{}⟦{{m}}^{{4}}⟧& {439164.}{}⟦{{m}}^{{4}}⟧\\ {768537.}{}⟦{{m}}^{{4}}⟧& {816124.}{}⟦{{m}}^{{4}}⟧\end{array}\right]$ (6)