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

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : indexfcn/Units

The Units Indexing Function

 

Description

Examples

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.

MMatrix2,i,j10i+jUnitm,shape=Unitm,datatype=float8

M11.m12.m21.m22.m

(1)

splitrtable_split_unitM

splitm,11.12.21.22.

(2)

default_unitsplit1

default_unitm

(3)

datasplit2

data11.12.21.22.

(4)

newdatadata4

newdata413557.439164.768537.816124.

(5)

newMrtable_set_indfnnewdata,Units:-Simple:-simplifydefault_unit4

newM413557.m4439164.m4768537.m4816124.m4

(6)

See Also

Array

Matrix

rtable

rtable_indexfcn

rtable_set_indfn

rtable_split_unit

Units

Units:-Simple