Defining a Unit

Tutorial - Using Units

Defining a Unit in a Worksheet

Although Mathcad provides a collection of built-in units, you may want to define your own. To define a typical multiplicative unit:

  1. Type the name of the unit you want to define - in this example, nanoamperes.

    Enter the abbreviation

  2. Press [:] to insert the definition symbol, :=. A placeholder appears.

    Type ':' for a placeholder

  3. In the placeholder, define your new unit.

    Define the unit

Unit functions

Mathcad can also use "unit functions" to associate a quantity with a value, or to scale the value. When defining a value, the function is applied, and when scaling a result, the inverse function is applied. The temperature units °C and °F are defined this way.

You can define your own unit function pairs. For example, you may wish to use the decibel scale and make use of dB like other unit names. To define a unit scaling function:

  1. Type the name of the unit function you want to define, followed by (x) - in this example, dB.

    dB(x)

  2. Press [:] to insert the definition symbol, :=. A placeholder appears.

  3. In the placeholder, define your function.

    dB(x):=10x/20

  4. Define an inverse function following the same steps, but precede the function name with /.

    /dB(x):= 20·log(x)

The function name is used to define variables using the postfix operator. The inverse function is used when you type the name, without the slash, in the units placeholder. You can get the / character in a math region either by typing in a special keystroke mode, or using the Custom Characters toolbar.

Note:

Defining Custom Built-In Units

There may be cases where a unit is so common in your organization's work that you want to make a new built-in unit. You can add built-in units to any of Mathcad's unit systems. These units are then understood in any Mathcad worksheet opened in a copy of Mathcad that has the modified files.

You must edit several of Mathcad's operating files to add unit definitions. Warning: as with all changes that may affect your ability to run Mathcad, we recommend making copies of files before you change them. Typos and syntax errors in these files will cause Mathcad to stop functioning.

Edit the XML and MPL unit files in your Mathcad installation directory. For example, to add a unit to the SI unit system, edit

The first file contains the unit symbols and quantities required for the Insert Unit dialog box. The second file contains the actual definition of the unit. So, for example, to add the unit mJ, millijoule, do the following:

  1. Open the file /units/unit-system-SI.xml from the Mathcad install directory.
  2. Choose a quantity to associate with your unit. In this case, mJ is a unit of energy. If there is no existing quantity for your unit, you have to make one, following the examples in the XML. You need not supply all translations for the <displayName> if you are only supporting a single language, but you must at least supply the English name, used as the default.
  3. Create a new <unit></unit> entry in the file. Typically, these are listed in the file by quantity, so you can find the entry later. The easiest way to add a new unit is to copy and paste everything between a pair of existing <unit> tags and modify the new entry. In this case, copy the entry for Joule, and change the unit name, symbol name, and display name.
  4. Save and close the file.
  5. Open the file /mpl/mcdunitssystemsi.mpl file. New units are added with the prefix mc_<symbol> = rv(<value>); In the example case, add the entry
    mc_mJ = rv(milli joule);

    As with the XML file, it is easiest to copy and paste an existing example of syntax and edit appropriately. Entries in the MPL file are alphabetized by symbol. All entries in this file are based on existing units. The SI prefixes are defined, and may be used without a multiplication symbol. For more elaborate values, you may wish to add the value to the mcdunits.mpl file in the same directory. Follow the syntax and existing definitions in this file for performing multiplications and divisions.

  6. Save and close the file.
  7. Restart Mathcad. Test the name by typing and evaluating it:
    mJ = 1 × 10-3 J

Notes:

Related Topics