Difference between revisions of "Units"

From ZCubes Wiki
Jump to navigation Jump to search
Line 54: Line 54:
 
These conversions of scale follow the [https://en.wikipedia.org/wiki/Metric_prefix SI unit prefix standards].
 
These conversions of scale follow the [https://en.wikipedia.org/wiki/Metric_prefix SI unit prefix standards].
  
 +
{| class="infobox" cellpadding=1 style="padding:0; text-align:left;"
 +
! colspan="4" style="background:#ccf; text-align:center;" | [[Metric prefix]]es in everyday use
 +
|- style="background:#ccc;"
 +
! style="text-align:center;" | Text
 +
! style="text-align:center;" | Symbol
 +
! style="text-align:center;" | Factor
 +
! style="text-align:center;" | Power
 +
|-
 +
|exa
 +
| style="text-align: center;" |E
 +
| style="text-align: right;"  |{{val|1000000000000000000}}
 +
| style="text-align: center;" |10<sup>18</sup>
 +
|-
 +
|peta
 +
| style="text-align: center;" |P
 +
| style="text-align: right;"  |{{val|1000000000000000}}
 +
| style="text-align: center;" |10<sup>15</sup>
 +
|-
 +
|tera
 +
| style="text-align: center;" |T
 +
| style="text-align: right;"  |{{val|1000000000000}}
 +
| style="text-align: center;" |10<sup>12</sup>
 +
|-
 +
|giga
 +
| style="text-align: center;" |G
 +
| style="text-align: right;"  |{{val|1000000000}}
 +
| style="text-align: center;" |10<sup>9</sup>
 +
|-
 +
|mega
 +
| style="text-align: center;" |M
 +
| style="text-align: right;"  |{{val|1000000}}
 +
| style="text-align: center;" |10<sup>6</sup>
 +
|-
 +
|kilo
 +
| style="text-align: center;" |k
 +
| style="text-align: right;"  |{{val|1000|fmt=gaps}}
 +
| style="text-align: center;" |10<sup>3</sup>
 +
|-
 +
|hecto
 +
| style="text-align: center;" |h
 +
| style="text-align: right;"  |100
 +
| style="text-align: center;" |10<sup>2</sup>
 +
|-
 +
|deca
 +
| style="text-align: center;" |da
 +
| style="text-align: right;"  |10
 +
| style="text-align: center;" |10<sup>1</sup>
 +
|-
 +
|(none)
 +
| style="text-align: center;" |(none)
 +
| style="text-align: center;" |1
 +
| style="text-align: center;" |10<sup>0</sup>
 +
|-
 +
|deci
 +
| style="text-align: center;" |d
 +
| style="text-align: left;"  |0.1
 +
| style="text-align: center;" |10<sup>−1</sup>
 +
|-
 +
|centi
 +
| style="text-align: center;" |c
 +
| style="text-align: left;"  |0.01
 +
| style="text-align: center;" |10<sup>−2</sup>
 +
|-
 +
|milli
 +
| style="text-align: center;" |m
 +
| style="text-align: left;"  |0.001
 +
| style="text-align: center;" |10<sup>−3</sup>
 +
|-
 +
|micro
 +
| style="text-align: center;" |μ
 +
| style="text-align: left;"  |{{val|0.000001}}
 +
| style="text-align: center;" |10<sup>−6</sup>
 +
|-
 +
|nano
 +
| style="text-align: center;" |n
 +
| style="text-align: left;"  |{{val|0.000000001}}
 +
| style="text-align: center;" |10<sup>−9</sup>
 +
|-
 +
|pico
 +
| style="text-align: center;" |p
 +
| style="text-align: left;"  |{{val|0.000000000001}}
 +
| style="text-align: center;" |10<sup>−12</sup>
 +
|-
 +
|femto
 +
| style="text-align: center;" |f
 +
| style="text-align: left;"  |{{val|0.000000000000001}}
 +
| style="text-align: center;" |10<sup>−15</sup>
 +
|-
 +
|atto
 +
| style="text-align: center;" |a
 +
| style="text-align: left;"  |{{val|0.000000000000000001}}
 +
| style="text-align: center;" |10<sup>−18</sup>
 +
|-
 +
| colspan=4 style="background:#ddd; text-align:center" | {{navbar|Template:Common metric prefixes|mini=1}}
 +
|}
  
a=1m;
+
==Conversion among Unit Systems==
a<>Ym;
 
  
 +
z^3 supports conversion among unit systems, such as SI Units and FPS systems.
 +
 +
For example:
 +
 +
a=1mi;
 +
1 mi.
 +
 +
a<>km;
 +
1.6093439999999999 km.
 +
 +
Notice that the mi (miles) unit of variable a is converted to km.
 +
 +
==Units on Array of Values==
 +
 +
Units work on variables as simple numerical values or as arrays.
 +
 +
Let us consider numbers 1 to 100.
 +
a=1..100;
 +
b=a<>(mi);
 +
 +
{| class="wikitable"
 +
|-
 +
! Numeric,Units !! UNITSOF
 +
|-
 +
| 1,mi || 1
 +
|-
 +
| 2,mi || 2
 +
|-
 +
| 3,mi || 3
 +
|-
 +
| 4,mi || 4
 +
|-
 +
| 5,mi || 5
 +
|-
 +
| 6,mi || 6
 +
|-
 +
| 7,mi || 7
 +
|-
 +
| 8,mi || 8
 +
|-
 +
| 9,mi || 9
 +
|-
 +
| 10,mi || 10
 +
|}
 +
 +
Now b has the values 1..100 in miles.
 +
 +
Let us convert all of these values to km.
 +
b<>km;
 +
 +
The answer is given as:
 +
{| class="wikitable"
 +
|-
 +
! Numeric,Units !! UNITSOF
 +
|-
 +
| 1,km || 1.6093439999999999
 +
|-
 +
| 2,km || 3.2186879999999998
 +
|-
 +
| 3,km || 4.828031999999999
 +
|-
 +
| 4,km || 6.4373759999999995
 +
|-
 +
| 5,km || 8.046719999999999
 +
|-
 +
| 6,km || 9.656063999999999
 +
|-
 +
| 7,km || 11.265407999999999
 +
|-
 +
| 8,km || 12.874751999999999
 +
|-
 +
| 9,km || 14.484096
 +
|-
 +
| 10,km || 16.093439999999998
 +
|}
 +
 +
 +
 +
--------------------
  
a=1mi;
 
a<>km;
 
 
a=1..100
 
b=a<>(mi);
 
b<>km; // titles still have chinese in production.
 
  
 
a=(1..100)<>℃
 
a=(1..100)<>℃

Revision as of 09:28, 13 June 2016

How to specify units

Units are a unique, inherent and simple feature of the z^3 language.

Using units is simple and easy. For example:

a=1m;

indicates that a is now a variable containing the value of 1 meter. For more complex units we can enclose them in brackets as in 3(m/sec).

If a variable needs to be specified in specific units, simply use the <> operator. Such as: a<>(m/sec);

In z^3 language, <> is the unit conversion operator. Also, any arithmetic operator such as +, -, *, /, ^, % etc. should be enclosed within < and > to allow unit conversions to propagate through these operations. These conversion operations can be done on arrays as parameters also. Hence to add a meter to 2 centimeters, do the following: a=1m<+>2cm; and z^3 will give the answer: 102 cm.

Note, that this result now carries the units with it for further operations. For example: a=(1m<+>2cm)<^>3; gives the answer as 1061208 cm3.

To convert the current value of a variable to a different unit, simply use the <> operator: a<>cm;

Notice that if a already had a unit, it will be appropriately converted using the units. If it did not have units inherently, it will simply be given the units. $> a=1 1 $> a<>cm; 1 cm.

$> a=1m; 1 m. $> a<>cm; 100 cm.

In the second case, 1m is converted to 100cm.

Unit Prefixes

Similarly, scales such as milli, mega, etc. are supported using conventional SI units. a=1m; 1 m. a<>ym; 1.0000000000000001e+24 ym.

Here a now has the unit yoctometer.

Using uppercase Y, we get the answer in Yottameter. a=1m; 1 m. a<>Ym; 1.0000000000000001e-24 Ym.

These conversions of scale follow the SI unit prefix standards.

Metric prefixes in everyday use
Text Symbol Factor Power
exa E Template:Val 1018
peta P Template:Val 1015
tera T Template:Val 1012
giga G Template:Val 109
mega M Template:Val 106
kilo k Template:Val 103
hecto h 100 102
deca da 10 101
(none) (none) 1 100
deci d 0.1 10−1
centi c 0.01 10−2
milli m 0.001 10−3
micro μ Template:Val 10−6
nano n Template:Val 10−9
pico p Template:Val 10−12
femto f Template:Val 10−15
atto a Template:Val 10−18
Template:Navbar

Conversion among Unit Systems

z^3 supports conversion among unit systems, such as SI Units and FPS systems.

For example:

a=1mi; 1 mi.

a<>km; 1.6093439999999999 km.

Notice that the mi (miles) unit of variable a is converted to km.

Units on Array of Values

Units work on variables as simple numerical values or as arrays.

Let us consider numbers 1 to 100. a=1..100; b=a<>(mi);

Numeric,Units UNITSOF
1,mi 1
2,mi 2
3,mi 3
4,mi 4
5,mi 5
6,mi 6
7,mi 7
8,mi 8
9,mi 9
10,mi 10

Now b has the values 1..100 in miles.

Let us convert all of these values to km. b<>km;

The answer is given as:

Numeric,Units UNITSOF
1,km 1.6093439999999999
2,km 3.2186879999999998
3,km 4.828031999999999
4,km 6.4373759999999995
5,km 8.046719999999999
6,km 9.656063999999999
7,km 11.265407999999999
8,km 12.874751999999999
9,km 14.484096
10,km 16.093439999999998




a=(1..100)<>℃ b=a<>℉

E:=(m<>kg)*(SPEEDOFLIGHT()<^>2); E(2kg)

a=1mi; b=10km; [a,b,(a<+>b)<>mi]

10mi<>km

Pi seems to be obfuscated.

SIN(90<>deg)

(rad2piby10)<>rad<>deg

((rad2piby10)<>rad<>deg)@SIN .graphin() //did not work in safari. (1..10)<>kg

b=(100$<+>3020¢); b<>$;

SETCONVERSION(1<>euro,1<>dollar,1.1)

SETCONVERSION(1$,1€,0.9); PRINTCONVERSION(); 345$<>€

1$<>1₹ // without conversion will fail.

(1..100)<>℃<>℉

SETCONVERSION(1<>€,1<>$,1.1); (1..100)<>€<>$

SETCONVERSION(1<>€,1<>$,1.10); (1..1000..10)<>€<>$

SETCONVERSION(1<>€,1<>$,1.10); (0..1000..20)<>€<>$

UNITIFY([1m,2m,3cm])

SUM(UNITIFY([1m,2m,3mm]))

(100$<+>300¢<+>30¢)<>$ PMT(4%,12,1000$,120000¢,0)

PMT(4%,12,1000$,1200.00¢,0) PMT(4%,12,1000$,120000¢,0)

1<>gal<>l 1<>l<>oz

(1..100)<>l<>ul 1Pa<>atm

E:=(m<>kg)<*>(SPEEDOFLIGHT()<^>2); b=E(2g); ConvertToUnitOfNature(b,"energy")

1m<>>1cm;

[1m,2m]<>>[1cm,200cm];

[1m,2m]<>=>[1cm,200cm];

[1m,2m]<<>[1cm,200cm];

[1m,2m]<<>[1cm,200cm];

[1m,2m]<==>[1cm,200cm];

[1m,2m]<!=>[1cm,200cm];

[1m,2m]<<=>[1cm,199.99cm];

[1m,2m]<<=>[1cm,200.01cm];

((1..10)<>m)<>>3m;

((0.1..10)<>m)<>>30cm


CONSTANT("G") CONSTANT("G")<*>1kg<*>110kg</>(6000m<^>2) // did not work.

(CONSTANT("G")<*>1kg<*>110kg)</>((6000m)<^>2) // how to bracket the units to be inside and ignore < etc? // ## can be used to name variables with spaces in them. // the actual variable is named by removing the spaces. // otherwise it goes into code as it is. ##weight of zone=3m; ++(##weight of zone);

##weight of zone=3m; a=3.4mm<+>(##weight of zone);

//%G is gravitational constant GF:=%G*m1*m2/r^2; GF(1,2,300)

v:=u+%g*t; // this uses %g as default g value v(1,2)

%planck %boltzmann; %planck length;

PRINTCONVERSIONS() CONSTANTS() CONVERT()

A¹=34; A=[23,4,5,5]; /* no array indexing on subscript yet. Will decide on that later. */ A¹=[23,4,5,5] A¹[2]

a=%gravit; b=30<*>a

a=%gravit; b=(1..10)<*>a

E:=m<>kg<*>%c<^>2; E(1000kg) E(1000kg<>lbm) // - will gave same result as 1000kg E(1000lbm) //lbm is used for units of lb mass.

// %G<*>1kg<*>110kg(6000m<^>2) // %G<*>1kg<*>110kg((6000m)<^>2) // -did not work. Said 7.34149141e-9Nm3UNITPOWERUNITSOF %G<*>1kg<*>110kg<*>((6000m)<^>2)

%G<*>1kg<*>110kg</>((6000m)<^>2)


// make this work. 1..100 @> x.txt; // send output to a <@ x.txt; // read input from a;

1.3J<>GeV 1.3J<>eV

1J<>l.atm; // 0.0098692latm 1J<>(l.atm-1) // this should fail. and will keep original units. maybe safer. 1m2<>in2 1m²<>in²

10m2<>are 1m2<>are

100m2<>acre

E:=m<>kg<*>%c<^>2; b=E(1000kg)<>J

   c=b<>eV;

[b,c]

1..100.$("[SIN(x),COS(x),TAN(x)]") 1..100.$([SIN,COS,TAN]) worked. 1..100.$("[x,x^2,x^3,x^4,x^3+x^4,SIN(x)]") works 1..100.$("[SIN(x),COS(x),TAN(x)]") 1..100.$([SIN,COS,TAN]) x=SERIESOF("1/x",9,10) //this is to from in parameter sequence. x=SERIESOF("1/x",19,10) SERIESOF("1/x",10,5) x=SERIESOF "1/LOG(x,2)" 100 1 x=SERIESOF "1/log2x" 100 91 //removed: 1..10.$_([+,-]) 1..10.$_([SUM,MINUS]) //removed: 1..10.$_|+| EXPOF(5) [SIN,COS]@[1..100] 1..10.$_("+") 1..10.$_("+") 1..10@["+"] 1..10@"+"

(1..100)<>m<+>10cm

MAGICSQUARE(3).$$(SUM) MAGICSQUARE(3).$$$(SUM) MAGICSQUARE(3).$_(SUM)

a=1m<>mm<+>400km 1m<>eor // should give nothing as there is no such conversion. (((1..100)<>m)<^>2)<>are

(1..1000)<>$ (((1..100)<>m)<^>2)<>km2 // why chinese headers here?

(1..100)m<>cm

F=%G<*>100kg<*>10g</>((100km)<^>2);

1.3J<>GeV //check this

velocity=3<>(m/sec); time=1hr; velocity<*>time;

1(g.m)<>(mg.cm)

a=LAZYRANGE(1,100) a(1..100) // generate numbers in the range at that interval, without having to generate the array ahead of time. Useful in things like INTEGRALS etc. a() a=LAZYOBJECT(1,100,1000) // can even take a(0.1); a.islazyrange()


1(kg.m2s-2)<>(N.m) 1(kg.m2s-2)<>J 1(kg.m2s-2)<>(N) // also should work as we want to get rid of the /s here in this case. 1(kg.m2s-2)<>(N.m2) // should fail. 1(kg.m2s-2)<>(J/s) // should fail. 1(kg.m2s-3)<>(J/s) 1(kg.m2.s)<>(J/s) // should this fail? it works now.

12(g.m-1/s)<>(g.cm) // should fail. 12(g.m)<>(g.mm) // should not fail. 12(g.m)<>(g.cm) // should not fail.

12(g.m)<>(g.s) // should fail. original should be returned. 12(g.m)<>(g.mm) 12(g.m)<>(g.s) 12(g.m-1)<>(g.mm-1) 12(g.m-1/s)<>(g.cm-1) // converts, but this is ok, since /s on left sometimes we want to get rid off for some reason for using it on another calculation. Say N/s but you only want to use the N on it. 1(kg.m2/s2)<>e // how to make this conversion?

1(kg.m2/s2)<>J<>e

1.3(kg.m2/s2)<>Jo // would fail and original will be kept.

(((1..100)<>m)<^>2)<>are (1..100)<>are [1cm2,2m2]<>are %pi*34; %e; %avo;

q=1(mol/s); heat=%avo<*>q;

1Pa<>atm 1atm<>psi 1atm<>hPa

a=1<>(kg/m.s-2)<>Pa<>torr 1J<>BTU 1ly<>m 10ly<>m<>km

1atm<>inHg<>mmHg

1atm<+>1bar (1atm<+>1bar)<>atm 1km<>m<>lightyear

1lightyear<>km

1lightyear<>pc

1m<>ly

1km<>ly //seemed off. this is possibly correct. (1km<+>1ly)<>km

1Å<>km

1Å<>m

(1..100)<>AU<>m

1degree<>arcminute

1Tsec<>sec

1(m/s)<>(km/hr) 1(km/s)<>(km/hr)

1(cal/mn)<>(J/sec) // d

1(kg/m3)<>(slug.ft-3)

2(rad/sec)<>rpm // did not convert. not sure why.

(1..100)<>USD<>EUR

SUPPORTEDUNITS()

1nibble<>bit 102400000000bit<>MB 1kB<>MB // seems wrong. 1kB<>Mb 1(kb)<>(bit) Pi<>(rad/sec)<>rpm 1(rad/sec)<>rpm 1(rad/mn)<>rpm (1(rad/mn)<>rpm)*2*Pi // should give 1. 1(rotation/mn)<>rpm 1(cycle/mn)<>(rad/mn)

1(cycle/mn)<>rpm

60rad<>deg 60rad<>deg<>rotation

1MB<>kB 1B<>kB 1MB<>B 1kB<>B

a=1(kg/m/s-2/t3) a=1(kg/m/s-2/t3) a=1(kg/m/s-2/t3) a=1(kg/m/s-2/t3) a=1<>(kg/m.s-2) // this worked though.

1(kg/m3)<>(slug/ft^3) // will not work due to ^. 1(kg/m3)<>(slug/ft3) //works 1(kg/m3)<>(slug.ft-3) //works

1(s-1)<>Hz 1(mn-1)<>Hz

velocity=3<>(m/s); time=1hr; velocity<*>time;

(((1..100)<>m)<^>2)<>acre

((1..100)<>m)<^>2