Units

SpeQ supports units on the areas of mechanics, electricity, temperature, and more. By using units you can make calculations with physical quantities easier and more reliable, because you can no longer make conversion mistakes (for example between meters, millimeters and inches). SpeQ automatically applies the right proportions. All SI units and US units are included. Additionally, you can also define your own units, as explained on the page Defining units.

All built-in units are listed on the page Units Overview. The available units are also listed in the Functionstree.

Units can be used in the following way:
' Examples of basic use of units

0.2 m * 12.1 cm
       Ans = 242 cm²

0.8 m + 12 inch
       Ans = 1.1048 m

3 m/s + 18 km/h
       Ans = 8 m/s

3.2 V / 5 A
       Ans = 0.64 Ohm
Units are case sensitive. For example the prefixes m (milli) and M (mega) have a different meaning. So "2.5 mm" is not the same as "2.5 Mm".

You can use suffixes as exponents, for example "4.5 m3" means 4.5 cubic meter.
4.5 m3 In litre
       Ans = 4500 litre
Units can be overwritten by variable definitions. This can lead to strange error messages. For example when you define a variable "m = 2.5", the unit m (meter) is overwritten and can no longer be used. The unit m will no longer be recognized.
' Overwritten unit
m = 2.5
       m = 2.5
3 m + 5.2 m
       Error: Unit m is overwritten by an user defined variable
Back to top

Implicit multiplication

You can enter a unit right behind a value. SpeQ calculates this as an implicit multiplication. For example "2.3 m" is calculated as "2.3 * m". It is important to realize that the implicit multiplication has lower precedence than the normal multiplication and division. Thus, "1/2 m" is calculated as "1/(2*m)" and not as "(1/2)*m". Note that this works different in older versions of SpeQ, where implicit multiplication has the same precedence.
' Be aware of the precedence of implicit multiplication with units
1/2 m
       Ans = 0.5/m
(1/2) m
       Ans = 0.5 m
Back to top

Conversion

To convert from one unit to another, you can use the operator In or the function Convert(x, unit). This way you can change the unit from meters to inches, or from Farenheit to Celsius.
' Get the answer in a specific unit

15 inch In m
       Ans = 0.381 m

Convert(inch, cm)
       Ans = 2.54 cm

8 m/s In km/h
       Ans = 28.8 km/h

34.5 °C In °F
       Ans = 94.1 °F
To remove a unit from a value, you can also use the function Convert and just don't specify the unit.
' Remove unit
a = 3.5 m²;
Convert(a)
       Ans = 3.5
The differences between In and Convert are:
  • the operator In supports lists, and the function Convert not.
  • With the function Convert you can remove the unit from a value.
Back to top

Examples

'Examples of using units

2.3 m + 55 cm
       Ans = 2.85 m

3 m/s + 18 km/h
       Ans = 8 m/s

2.5m * 3m
       Ans = 7.5 m²

' You can use suffixes as exponent, such as m3 for cubic meter
4.5 m3 In litre
       Ans = 4500 litre

' Be aware of the precedence of implicit multiplication with units
' The following expression does not give what you probably intended:
1/2 m
       Ans = 0.5/m
' Therefore use parentheses:
(1/2) m
       Ans = 0.5 m

' Calculate the distance that you can travel in
' 15 minutes when you have a speed of 120 km/h
speed = 120 km/h;
time = 15 minutes;
distance = speed * time
       distance = 30 km

' Calculate the speed that an object has after 
' 5 seconds when you let it fall.
' Note: you can insert a square character (²) by
' pressing Ctrl+2, and a (³) by pressing Ctrl+3
g = 9.81 m/s²;
t = 5 s;
speed = g * t
       speed = 49.05 m/s

' Calculate the force acting on a mass
mass = 3.5 kg;
F = mass * g
       F = 34.335 N

' Get the answer in a specific unit
15 inch In m
       Ans = 0.381 m
inch In cm
       Ans = 2.54 cm
8 m/s In km/h
       Ans = 28.8 km/h
' Or use the function Convert
Convert(15 inch, m)
       Ans = 0.381 m
' You can use Convert also to remove the unit
Convert(mass)
       Ans = 3.5

' Calculate the volume of a cube
w = 3.25 m;
d = 4.10 m;
h = 2.20 m;
volume = w * d * h
       volume = 29.315 m³

' Overwriting units
' It can easily happen that you overwrite a unit by defining
' a variable or function.
m = 4.6
       m = 4.6
' In the following expression m is not recognized as unit meter 
' because it is overwritten by the variable m.
3 m + 5.2 m
       Error: Unit m is overwritten by an user defined variable

Clear(m);  ' remove the variable again

' Angles
Sin(45°) ^ 2
       Ans = 0.5
Convert(90°, Rad)
       Ans = 1.570796327 Rad

' Temperatures
34.5 °C In °F
       Ans = 94.1 °F

' Forces
4 N + 5 kg*m/s²
       Ans = 9 N

' Pressure
5 N/m² + 1.5 Pa + 0.001 Bar
       Ans = 106.5 Pa

' Electricity
3.2 V / 5 A
       Ans = 0.64 Ohm
(220 V) * (0.18 A)
       Ans = 39.6 W
Back to top

See Also

Defining units, Defining variables, Functionstree, Units Overview, Wikipedia