Difference between revisions of "Units in Matlab"

From biophysics
Jump to navigation Jump to search
(Created page with "==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....")
 
Line 14: Line 14:
 
Candela (cd) - Unit of luminous intensity
 
Candela (cd) - Unit of luminous intensity
 
</pre>
 
</pre>
Cominations of these units like m/s are also considered 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/s²)
 
  
 +
Combinations of these units like m/s are also considered basic 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/s²).
  
The main rule is:
+
SI-units with prefixes are '''not''' considered basic SI-units.
* Use only variables in SI units inside a program
 
* Do calculations only on basic SI units
 
  
* When using
+
The main rules are:
* If an interface (input or output) has other units convert them to SI units
+
* Use only variables in basic SI-units inside a program as much as possible.
 +
* Do calculations only on basic SI-units as much as possible.
 +
* Avoid use SI-units with prefixes like nanometer or millisecond as much as possible.
 +
* If an input interface has non-standard SI units, convert them to SI-units as soon as you read them from the interface.
 +
* If an output interface needs non-standard SI units, convert the from SI-units as late as possible, just before outputting them.
 +
* When you need a different unit for some reason in you program, make it explicit by using a suffix like "_nm" or "_gallon".

Revision as of 13:01, 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 as possible!

We have the 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 also considered basic 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/s²).

SI-units with prefixes are not considered basic SI-units.

The main rules are:

  • Use only variables in basic SI-units inside a program as much as possible.
  • Do calculations only on basic SI-units as much as possible.
  • Avoid use SI-units with prefixes like nanometer or millisecond as much as possible.
  • If an input interface has non-standard SI units, convert them to SI-units as soon as you read them from the interface.
  • If an output interface needs non-standard SI units, convert the from SI-units as late as possible, just before outputting them.
  • When you need a different unit for some reason in you program, make it explicit by using a suffix like "_nm" or "_gallon".