Difference between revisions of "Units in Matlab"
Line 21: | Line 21: | ||
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 defined as ''basic'' SI-units. Units with prefixes do not fall under this definition. | + | ''Primary'' and ''derived'' SI-units will be here defined as ''basic'' SI-units. Units with prefixes do not fall under this definition. |
Some commonly used derived SI-units: | Some commonly used derived SI-units: |
Revision as of 14:07, 18 March 2024
Introduction
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!
SI units
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 like m/s are considered derived SI-units, and also 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 commonly used derived SI-units:
Joule (energy) Coulomb (electric charge) Voltage (electric potential) Ohm (electric resistance) Farad (electric capacitance) Tesla (magnetic field strength) Newton (force) Watt (power) Pascal (pressure)
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 SI 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 SI units, convert them from SI-units as late as possible before outputting them.