Main Content

newUnit

Define new unit

Description

example

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

Examples

Define New Unit and Rewrite Unit

Load the collection of symbolic units by usingsymunit. Find information on the predefined unitu.c_0光的速度。

u = symunit; unitInfo(u.c_0)
speed of light in vacuum - a physical unit of velocity. Get all units for measuring 'Velocity' by calling unitInfo('Velocity').

Show that the exact value of the speed of light in SI is299792458metres per second.

c = unitConvert(u.c_0,'SI')
c = 299792458*([m]/[s])

Define the new unitspeedOfLightApproxfor the approximate value of the speed of light as3e8meters per second.

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

Alternatively, you can specify the unit by usingu.speedOfLightApprox.

Define the equationE=mc2using the new unit.

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

RewriteEin 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, rewriteEin terms ofJoule.

E = rewrite(E,u.Joule)
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 any of its alternate names.

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), whereu = symunit, defines workday as a unit representing 8 hours.

Version History

Introduced in R2017a