Difference between revisions of "Units in Matlab"
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | __TOC__ | ||
==Introduction== | ==Introduction== | ||
When working with quantities we often have to know what the units are in which the quantities are expressed. There are several ways to use variables with units in a program. | When working with quantities we often have to know what the units are in which the quantities are expressed. There are several ways to use variables with units in a program. | ||
Line 18: | Line 19: | ||
</pre> | </pre> | ||
− | Combinations of these units | + | Combinations of these units are considered '''derived''' SI-units. These are units like m/s and units that can be expressed in terms of SI-units but have their own name, like: Newton (kg.m/s²) or Pascal (N/m²). |
SI-units with prefixes like ''millisecond'' or ''centimeter'' are '''not''' considered primary or derived SI-units. | SI-units with prefixes like ''millisecond'' or ''centimeter'' are '''not''' considered primary or derived SI-units. | ||
− | ''Primary'' and ''derived'' SI-units will be here defined as ''basic | + | ''Primary'' and ''derived'' SI-units will be here defined as '''basic SI-units'''. Units with prefixes do not fall under this definition. |
− | Some | + | Some common derived SI-units are: |
<pre> | <pre> | ||
Joule (energy) | Joule (energy) | ||
Line 35: | Line 36: | ||
Watt (power) | Watt (power) | ||
Pascal (pressure) | Pascal (pressure) | ||
+ | </pre> | ||
+ | |||
+ | By using basic SI-units formulae can be expressed in their simplest form. | ||
+ | Examples: | ||
+ | <pre> | ||
+ | pressure = force / area | ||
+ | power = potential * current | ||
</pre> | </pre> | ||
Line 51: | Line 59: | ||
summary: | summary: | ||
<pre> | <pre> | ||
− | Basic SI-units: implicit | + | Basic SI-units: implicit (preferred) |
Other units : explicit by using suffixes | Other units : explicit by using suffixes | ||
</pre> | </pre> |
Latest revision as of 10:31, 19 March 2024
Introduction
When working with quantities we often have to know what the units are in which the quantities are expressed. There are several ways to use variables with units in a program.
Space probes have crashed on Mars due to invalid assumptions about units for some variables. So how can we avoid this type of disasters? We have to make it as simple and explicit as possible. But most importantly we have to have rules and stick to it!
SI units
In science we have the primary SI-units of the Franse Système international d'unités:
Meter (m) - Unit of length Kilogram (kg) - Unit of mass Second (s) - Unit of time Ampere (A) - Unit of electric current Kelvin (K) - Unit of temperature Mole (mol) - Unit of amount of substance Candela (cd) - Unit of luminous intensity
Combinations of these units are considered derived SI-units. These are units like m/s and units that can be expressed in terms of SI-units but have their own name, like: Newton (kg.m/s²) or Pascal (N/m²).
SI-units with prefixes like millisecond or centimeter are not considered primary or derived SI-units.
Primary and derived SI-units will be here defined as basic SI-units. Units with prefixes do not fall under this definition.
Some common derived SI-units are:
Joule (energy) Coulomb (electric charge) Voltage (electric potential) Ohm (electric resistance) Farad (electric capacitance) Tesla (magnetic field strength) Newton (force) Watt (power) Pascal (pressure)
By using basic SI-units formulae can be expressed in their simplest form. Examples:
pressure = force / area power = potential * current
Programming rules
Primary rules:
- Use basic SI-units as much as possible.
- Use of basic SI-units is implicit: variables like someLength, someTime, someVolume are assumed in SI-units.
- Variables in non-basic SI-units like nanometer, millisecond or liter should have explicit suffixes like someLength_nm, someTime_ms or someVolume_liter.
- Use of radians for angles is implicit. When using degrees use the suffix "_deg".
Secondary rules:
- If an input interface has non-basic units, convert them to basic SI-units as soon as possible after you read them from the interface.
- If an output interface needs non-basic units, convert them from basic SI-units as late as possible before outputting them.
- If you need to deviate from the primary rules make it explicit with comments.
summary:
Basic SI-units: implicit (preferred) Other units : explicit by using suffixes