# newUnit

Define new unit

## Syntax

``c = newUnit(name,definition)``

## Description

example

````c = 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 any of its alternate names.```

## Examples

### Define New Unit and Rewrite Unit

Load the collection of symbolic units by using `symunit`. Find information on the predefined unit `u.c_0` for the speed of light.

```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 is `299792458` metres per second.

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

Define the new unit `speedOfLightApprox` for the approximate value of the speed of light as `3e8` meters per second.

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

Alternatively, you can specify the unit by using `u.speedOfLightApprox`.

Define the equation E = mc2 using the new unit.

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

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

## Version History

Introduced in R2017a