newUnitSystem

Define unit system

Description

example

newUnitSystem(name,baseUnits) defines a new Unit System with the name name and the base units baseUnits. Now, you can convert units into the new unit system by using rewrite. By default, available unit systems include SI, CGS, and US. For all unit systems, see Unit Systems List.

example

newUnitSystem(name,baseUnits,derivedUnits) additionally specifies the derived units derivedUnits.

Examples

collapse all

A unit system is a collection of units to express quantities. The easiest way to define a new unit system is to modify a default unit system, such as SI, CGS, or US.

Modify SI to use kilometer for length and hour for time by getting the base units using baseunits and modifying them by using subs.

u = symunit;
SIUnits = baseUnits('SI')
SIUnits =
[ [kg], [s], [m], [A], [cd], [mol], [K]]
newUnits = subs(SIUnits,[u.m u.s],[u.km u.hr])
newUnits =
[ [kg], [h], [km], [A], [cd], [mol], [K]]

Note

Do not define a variable called baseUnits because the variable will prevent access to the baseUnits function.

Define the new unit system SI_km_hr using the new base units.

newUnitSystem('SI_km_hr',newUnits)
ans =
"SI_km_hr"

Rewrite 5 meter/second to the SI_km_hr unit system. As expected, the result is in terms of kilometers and hours.

rewrite(5*u.m/u.s,'SI_km_hr')
ans =
18*([km]/[h])

Specify a new unit system by specifying the base and derived units directly. A unit system has up to 7 base units. For details, see Unit System.

Define a new unit system with these base units: gram, hour, meter, ampere, candela, mol, and celsius. Specify these derived units: kilowatt, newton, and volt.

u = symunit;
sysName = 'myUnitSystem';
bunits = [u.g u.hr u.m u.A u.cd u.mol u.Celsius];
dunits = [u.kW u.N u.V];
newUnitSystem(sysName,bunits,dunits)
ans =
"myUnitSystem"

Rewrite 2000 Watts to the new system. By default, rewrite uses base units, which can be hard to read.

rewrite(2000*u.W,sysName)
ans =
93312000000000000*(([g]*[m]^2)/[h]^3)

Instead, for readability, rewrite 2000 Watts to derived units of myUnitSystem by specifying 'Derived' as the third argument. Converting to the derived units of a unit system attempts to select convenient units. The result uses the derived unit, kilowatt, instead of base units. For more information, see Unit Conversions and Unit Systems.

rewrite(2000*u.W,sysName,'Derived')
ans =
2*[kW]

Input Arguments

collapse all

Name of unit system, specified as a string or character vector.

Base units of unit system, specified as a vector of symbolic units. The base units must be independent in terms of the dimensions mass, time, length, electric current, luminous intensity, amount of substance, and temperature. Thus, in a unit system, there are up to 7 base units.

Derived units of unit system, specified as a vector of symbolic units. Derived units are optional and added for convenience of representation.

collapse all

Unit System

A unit system is a collection of base units and derived units that follows these rules:

• Base units must be independent in terms of the dimensions mass, time, length, electric current, luminous intensity, amount of substance, and temperature. Therefore, a unit system has up to 7 base units. As long as the independence is satisfied, any unit can be a base unit, including units such as newton or watt.

• A unit system can have less than 7 base units. For example, mechanical systems need base units only for the dimensions length, mass, and time.

• Derived units in a unit system must have a representation in terms of the products of powers of the base units for that system. Unlike base units, derived units do not have to be independent.

• Derived units are optional and added for convenience of representation. For example, kg m/s2 is abbreviated by newton.

• An example of a unit system is the SI unit system, which has 7 base units: kilogram, second, meter, ampere, candela, mol, and kelvin. There are 22 derived units found by calling derivedUnits('SI').