newUnit

Define new unit

Syntax

newUnit(name,definition)

Description

example

newUnit(name,definition) defines the new unit name using the expression definition. The definition must be in terms of existing symbolic units. You cannot redefine a predefined unit or its alternate names.

Examples

Define New Unit and Rewrite Unit

Define the new unit speedOfLight as 3e8 meters per second.

u = symunit;
c = newUnit('speedOfLight',3e8*u.m/u.s)
c =
[speedOfLight]

Define the famous equation E = mc2 using the new unit.

syms mass
m = mass*u.kg;
E = m*c^2
E =
mass*[kg]*[speedOfLight]^2

Alternatively, you can specify the unit by using u.SpeedOfLight.

Rewrite E in terms of meters per second.

E = rewrite(E,u.m/u.s)
E =
90000000000000000*mass*(([kg]*[m]^2)/[s]^2)

Since the standard unit of energy is the Joule, rewrite E in terms of Joule.

E = rewrite(E,u.J)
E =
90000000000000000*mass*[J]

Input Arguments

collapse all

Name of the new unit, specified as a character vector or string. You cannot redefine a predefined unit or its aliases.

Definition of the new unit, specified as a symbolic expression of units. The new unit must be defined in terms of existing symbolic units. For example, newUnit('workday',8*u.hour) where u = symunit.

Introduced in R2017a